Advertisements
Advertisements
Question
Write a program to input and store roll numbers, names and marks in 3 subjects of n number students in five single dimensional array and display the remark based on average marks as given below : (The maximum marks in the subject are 100).
Average marks = `"Total marks"/3`
Average marks | Remark |
85 - 100 | Excellent |
75 - 84 | Distinction |
60 - 74 | First-class |
40 - 59 | Pass |
Less than 40 | Poor |
Solution 1
import java.io.*; class Result{ public static void main(String args[]) throws IOException{ InputStreamReader in = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(in); System.out.print("Number of students: "); int n = Integer.parseInt(br.readLine()); int roll[] = new int[n]; String name[] = new String[n]; int m1[] = new int[n]; int m2[] = new int[n]; int m3[] = new int[n]; int total = 0; double avg = 0.0; for(int i = 0; i < n; i++){ System.out.print("Roll number: "); roll[i] = Integer.parseInt(br.readLine()); System.out.print("Name: "); name[i] = br.readLine(); System.out.print("Marks 1: "); m1[i] = Integer.parseInt(br.readLine()); System.out.print("Marks 2: "); m2[i] = Integer.parseInt(br.readLine()); System.out.print("Marks 3: "); m3[i] = Integer.parseInt(br.readLine()); total = m1[i] + m2[i] + m3[i]; avg = total / 3.0; if(avg >= 85 && avg <= 100) System.out.println("EXCELLENT"); else if(avg >= 75 && avg < 85) System.out.println("DISTINCTION"); else if(avg >= 60 && avg < 75) System.out.println("FIRST CLASS"); else if(avg >= 40 && avg < 60) System.out.println("PASS"); else System.out.println("POOR"); } } }
Solution 2
import java.util.*;
class Q14{
public static void main(String args[]){
Scanner ob = new Scanner(System.in);
System.out.println("ENTER THE NO. OF STUDENTS");
int n = ob.nextInt();
int i, roll[] = new int[n];
String name[] = new String[n];
String r[] = new String[n]; // Remark
double A[] = new double[n]; // subject A
double B[] = new double[n]; // subject B
double C[] = new double[n]; // subject C
double avg[] = new double [n], tmp;
// INPUT LOOP
for (i = 0; i < n; i++)
{
System.out.print("Roll number: ");
roll[i] = ob.nextInt();
System.out.print("Name: ");
name[i] = ob.next();
System.out.print("Enter marks in 3 subjects \n");
A[i] = ob.nextDouble();
B[i] = ob.nextDouble();
C[i] = ob.nextDouble();
}
// AVERAGE AND GRADE CALCULATION
for (i = 0; i < n; i++)
{ ave[i] = (A[i] + B[i] + C[i]) / 3;
tmp = avg[i];
if (tmp >= 85 && tmp <= 100)
r[i] = "Excellent";
else if (tmp >= 75 && tmp <= 84)
r[i] = "Distinction";
else if (tmp >= 60 && tmp <= 74)
r[i] = "First Class";
else if (tmp >= 40 && tmp <= 59)
r[i] = "Pass";
else if (tmp < 40)
r[i] = "poor";
}
// OUTPUT LOOP
System.out.println("\nRESULT");
System.out.println("Roll no \t Average \t\t Remarks");
for (i = 0; i < n; i++)
System.out.println(name[i] + "\t\t" + (float)avg[i] + "\t\t" + [i]);
}}
APPEARS IN
RELATED QUESTIONS
What is meant by a package?
Name the operators listed below are
(i) <
(ii) + +
(iii) &&
(iv) ? :
State the difference between == operator and equals () method.
Using switch statement, write a menu-driven program for the following :
(i) To find and display the sum of the series given below :
S = x1 -x2 + x2 – x4 + x5 – x20
(where x = 2)
(ii) To display the following series :
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.
Write a Java expression for the following :
`sqrt(3"x"+"x"^2)/"a+b"`
Name the primitive data type in Java that is:
A 64-bit integer and is used when you need a range of values wider than those provided by int.
Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.
- &&
- %
- >=
- ++
The code obtained after compilation is known as ______.
Write the Java expression for (a + b)x.
Evaluate the expression when the value of x = 4;
x* = - - x + x + + + x