Advertisements
Advertisements
प्रश्न
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 |
Advertisements
उत्तर १
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");
}
}
}उत्तर २
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
संबंधित प्रश्न
What is meant by a package?
Write one difference between / and % operator.
Write down java expression for:
`"T" = sqrt("A"^2 + "B"^2 + "C"^2)`
Rewrite the following using ternary operator:
if (x%2 == o)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);
Write a Java expression for the following :
`sqrt(3"x"+"x"^2)/"a+b"`
Rewrite the following using ternary operator :
if (bill > 10000)
discount = bill * 10.0 / 100;
else
discount = bill * 5.0 / 100;Write a program in Java to accept a string in lower case and change the first letter of every word to upper case. Display the new string.
Sample input: we are in a cyber world
Sample output: We Are In Cyber World
Name the primitive data type in Java that is :
A single 16-bit Unicode character whose default value is ‘\u0000’.
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 ______.
