Computer Applications
Write a program in Java using arrays:
(a) To store the Roll No., Name and marks in six subjects for 100 students.
(b) Calculate the percentage of marks obtained by each candidate. The maximum marks in each subject are 100.
(c) Calculate the Grade as per the given criteria:
Percentage Marks | Grade |
---|---|
From 80 to 100 | A |
From 60 to 79 | B |
From 40 to 59 | C |
Less than 40 | D |
Answer
import java.util.Scanner;
public class KboatSDAGrades
{
public static void main(String args[]) {
final int TOTAL_STUDENTS = 100;
Scanner in = new Scanner(System.in);
int rollNo[] = new int[TOTAL_STUDENTS];
String name[] = new String[TOTAL_STUDENTS];
int s1[] = new int[TOTAL_STUDENTS];
int s2[] = new int[TOTAL_STUDENTS];
int s3[] = new int[TOTAL_STUDENTS];
int s4[] = new int[TOTAL_STUDENTS];
int s5[] = new int[TOTAL_STUDENTS];
int s6[] = new int[TOTAL_STUDENTS];
double p[] = new double[TOTAL_STUDENTS];
char g[] = new char[TOTAL_STUDENTS];
for (int i = 0; i < TOTAL_STUDENTS; i++) {
System.out.println("Enter student " + (i+1) + " details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
in.nextLine();
System.out.print("Name: ");
name[i] = in.nextLine();
System.out.print("Subject 1 Marks: ");
s1[i] = in.nextInt();
System.out.print("Subject 2 Marks: ");
s2[i] = in.nextInt();
System.out.print("Subject 3 Marks: ");
s3[i] = in.nextInt();
System.out.print("Subject 4 Marks: ");
s4[i] = in.nextInt();
System.out.print("Subject 5 Marks: ");
s5[i] = in.nextInt();
System.out.print("Subject 6 Marks: ");
s6[i] = in.nextInt();
p[i] = (((s1[i] + s2[i] + s3[i] + s4[i]
+ s5[i] + s6[i]) / 600.0) * 100);
if (p[i] < 40)
g[i] = 'D';
else if (p[i] < 60)
g[i] = 'C';
else if (p[i] < 80)
g[i] = 'B';
else
g[i] = 'A';
}
System.out.println();
for (int i = 0; i < TOTAL_STUDENTS; i++) {
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ p[i] + "\t"
+ g[i]);
}
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Write a program in Java to store 20 numbers in a Single Dimensional Array (SDA). Display the numbers which are prime.
Sample Input:n[0] n[1] n[2] n[3] n[4] n[5] … n[16] n[17] n[18] n[19] 45 65 77 71 90 67 … 82 19 31 52 Sample Output: 71, 67, 19, 31
Write a program in Java to accept 20 numbers in a single dimensional array arr[20]. Transfer and store all the even numbers in an array even[ ] and all the odd numbers in another array odd[ ]. Finally, print the elements of both the arrays.
Write a program to accept a list of 20 integers. Sort the first 10 numbers in ascending order and next the 10 numbers in descending order by using 'Bubble Sort' technique. Finally, print the complete list of integers.
Write a program to accept name and total marks of N number of students in two single subscript arrays name[ ] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student's total marks with the average.
[deviation = total marks of a student - average]