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
संबंधित प्रश्न
Write a difference between unary and binary operator.
Name the operators listed below are
(i) <
(ii) + +
(iii) &&
(iv) ? :
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 down java expression for:
`"T" = sqrt("A"^2 + "B"^2 + "C"^2)`
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
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
