Computer Applications
The annual examination result of 50 students in a class is tabulated in a Single Dimensional Array (SDA) is as follows:
Roll No. | Subject A | Subject B | Subject C |
---|---|---|---|
……. | ……. | ……. | ……. |
……. | ……. | ……. | ……. |
……. | ……. | ……. | ……. |
Write a program to read the data, calculate and display the following:
(a) Average marks obtained by each student.
(b) Print the roll number and the average marks of the students whose average is above. 80.
(c) Print the roll number and the average marks of the students whose average is below 40.
Java
Java Arrays
90 Likes
Answer
import java.util.Scanner;
public class KboatExamResult
{
public static void main(String args[]) {
final int TOTAL_STUDENTS = 50;
Scanner in = new Scanner(System.in);
int rollNo[] = new int[TOTAL_STUDENTS];
int sA[] = new int[TOTAL_STUDENTS];
int sB[] = new int[TOTAL_STUDENTS];
int sC[] = new int[TOTAL_STUDENTS];
double avg[] = new double[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();
System.out.print("Subject A Marks: ");
sA[i] = in.nextInt();
System.out.print("Subject B Marks: ");
sB[i] = in.nextInt();
System.out.print("Subject C Marks: ");
sC[i] = in.nextInt();
avg[i] = (sA[i] + sB[i] + sC[i]) / 3.0;
}
System.out.println("\nRoll No\tAverage Marks");
for (int i = 0; i < TOTAL_STUDENTS; i++) {
System.out.println(rollNo[i] + "\t" + avg[i]);
}
System.out.println("\nStudents with Average above 80:");
for (int i = 0; i < TOTAL_STUDENTS; i++) {
if (avg[i] > 80)
System.out.println(rollNo[i] + "\t" + avg[i]);
}
System.out.println("\nStudents with Average below 40:");
for (int i = 0; i < TOTAL_STUDENTS; i++) {
if (avg[i] < 40)
System.out.println(rollNo[i] + "\t" + avg[i]);
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
29 Likes
Related Questions
To get promotion in a Science stream, a student must pass in English and should pass in any of the two subjects (i.e.; Physics, Chemistry or Maths). The passing mark in each subject is 35. Write a program in a Single Dimension Array to accept the roll numbers and marks secured in the subjects for all the students. The program should check and display the roll numbers along with a message whether "Promotion is Granted" or "Promotion is not Granted". Assume that there are 40 students in the class.
Write a program to store 20 numbers in a Single Dimensional Array (SDA). Now, display only those numbers that are perfect squares.
n[0] n[1] n[2] n[3] n[4] n[5] … n[16] n[17] n[18] n[19] 12 45 49 78 64 77 … 81 99 45 33 Sample Output: 49, 64, 81
Write a program to accept the year of graduation from school as an integer value from the user. Using the binary search technique on the sorted array of integers given below, output the message "Record exists" if the value input is located in the array. If not, output the message "Record does not exist".
Sample Input:n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9] 1982 1987 1993 1996 1999 2003 2006 2007 2009 2010 Write a program to store 6 elements in an array P and 4 elements in an array Q. Now, produce a third array R, containing all the elements of array P and Q. Display the resultant array.
Input Input Output P[ ] Q[ ] R[ ] 4 19 4 6 23 6 1 7 1 2 8 2 3 3 10 10 19 23 7 8