Given a list of marks ranging from 0 to 100. Write a PROGRAM to compute and print the number of student should have obtained marks (a) in the range 81 to 100 (b) in the range 61 to 80 (c) in the range 41 to 60 (d) in the range 0 to 40. The PROGRAM should use a minimum number of if statement.

PROGRAM:

import java.util.*;
public class P7
{
public static ArrayList<Integer> marksList = new ArrayList<Integer>();
public static void main(String[] args)
{
marks();
int first=0;
int second=0;
int third=0;
int fourth=0;
for(int mark : marksList)
{
if(mark>=81 && mark<=100)
{
first++;
}
else if(mark>=61 && mark<=80)
{
second++;
}
else if(mark>=41 && mark<=60)
{
third++;
}
else if(mark <=40)
{
fourth++;
}
}
System.out.println("No of student in the range 81 to 100:"+first);
System.out.println("No of student in the range 61 to 80:"+second);
System.out.println("No of student in the range 41 to 60:"+third);
System.out.println("No of student in the range 0 to 40:"+fourth);
}

public static void marks()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Marks of " + (marksList.size() + 1) + " Student.");
int marks = sc.nextInt();
marksList.add(marks);
System.out.print("Do you want to take marks of another Student(Y/N)");
sc = new Scanner(System.in);
char c = sc.nextLine().toUpperCase().toCharArray()[0];
if (c == 'Y')
{
marks();
}
}
}

OUTPUT:

(Visited 1,580 times, 1 visits today)
Share with Friends :
Written by: