English

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

Advertisements
Advertisements

Question

Write a program in Java using arrays:

  1. To store the Roll No., Name and marks in six subjects for 100 students.
  2. Calculate the percentage of marks obtained by each candidate. The maximum marks in each subject are 100.
  3. 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 in Brief

Solution

import java.util.*;
public class AQ6{
public static void main(String args[]){
Scanner ob = new Scanner(System.in);
String name[] = new String[100];
int roll[] = new int[100]; 
int tot[] = new int[100], marks = 0;
double p[] = new double[100];
char gr[] = new char{100];
// INPUT
for (int i = 0; i < roll.length; i++)
{
System.out.print("Enter your Roll no: ");
roll[i] = ob.nextInt();
System.out.print("Enter your name : ");
name[i] = ob.next();
System.out.println("Enter the marks in SIX subjects");
// FOR EACH STUDENT - INPUT OF 6 SUBJECT MARKS
for (int j = 0: j < 6; j++)
{marks = ob.nextInt();
if (marks <= 100)
tot[i] = tot[i] + marks;
}
// TOTAL, PERCENTAGE, GRADE
p[i] = (tot[i} / 600.0) * 100; // percentage : (yourscore / totscore) * 100
if (p[i] >= 80 && p[i] <= 100)
gr[i] = 'A’;
else if (p[i] >= 60 && p[i] <= 79)
gr[i ]= 'B';
else if (p[i] >= 40 && p[i] <= 59)
gr[i] = 'C';
else if (p[i] < 40)
gr[i] = 'D’;
}
// OUTPUT
System.out.println("Name \t Marks% \t Grade"); 
for (int i = 0; i < roll.length; i++)
System.out.println(name[i] + "\t" + (float)p[i] + " \t " + gr[i]);
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [Page 240]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×