C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Student Range Program - Java Programs

A list contains marks in the subject Computer Applications for ‘N’ number of students. Write a program to create an array of size ‘N’ and store the marks. Check and print the number of students falling into the different ranges given below:

100 – 80
79 – 60
59 – 40
39 – 20
19 – 0

import java.util.Scanner; class Ranges{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("N = "); int n = Integer.parseInt(in.nextLine()); int a[] = new int[n]; int r[] = new int[5]; System.out.println("Enter marks:"); for(int i = 0; i < a.length; i++){ a[i] = Integer.parseInt(in.nextLine()); if(a[i] >= 80 && a[i] <= 100) r[0]++; else if(a[i] >= 60 && a[i] <= 79) r[1]++; else if(a[i] >= 40 && a[i] <= 59) r[2]++; else if(a[i] >= 20 && a[i] <= 39) r[3]++; else if(a[i] >= 0 && a[i] <= 19) r[4]++; } System.out.println("100 - 80: " + r[0]); System.out.println("79 - 60: " + r[1]); System.out.println("59 - 40: " + r[2]); System.out.println("39 - 20: " + r[3]); System.out.println("19 - 0: " + r[4]); } }

Output

 
 OUTPUT 1: 
N = 3
Enter marks:
45
66
73
100 - 80: 0
79 - 60: 2
59 - 40: 1
39 - 20: 0
19 - 0: 0
 OUTPUT 2: 
N = 5
Enter marks:
56
78
87
89
95
100 - 80: 3
79 - 60: 1
59 - 40: 1
39 - 20: 0
19 - 0: 0