English

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 : - Computer Applications

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
Answer in Brief

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");
        }
    } 
}
shaalaa.com

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]);
}} 
shaalaa.com
Introduction of Operators in Java
  Is there an error in this question or solution?
Chapter 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [Page 242]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 3 Arrays (Single Dimensional and Double Dimensional)
EXERCISES | Q VII. 14. | Page 242
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×