-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentMarksAnalyzer.java
More file actions
53 lines (44 loc) · 1.6 KB
/
StudentMarksAnalyzer.java
File metadata and controls
53 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class StudentMarksAnalyzer{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter markes of 5 studens:");
int[] marks = new int[5];
int sum = 0;
int studentsAboveAvg = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
// Get marks of 5 students also calculate sum and find min and max marks of students.
for(int i = 0 ; i < marks.length ;){
if(!sc.hasNextInt()){
System.out.println("Enter values makes!!");
sc.next();
continue;
}
marks[i] = sc.nextInt();
if(marks[i] > 100 || marks[i] < 0){
System.out.println("Enter values makes!!");
continue;
}
sum += marks[i];
max = max < marks[i] ? marks[i] : max;
min = min > marks[i] ? marks[i] : min;
i++;
}
float avgMarks = (float) sum / 5;
// Print all the marks.
System.out.print("\nAll Marks: ");
for(int mark:marks){
System.out.print(mark + " ");
if(mark > avgMarks){
studentsAboveAvg++;
}
}
System.out.println("\nTotal Marks = " + sum);
System.out.println("Average Marks = " + avgMarks);
System.out.println("Highest Marks = " + max);
System.out.println("Lowest Marks = " + min);
System.out.println("Students scoring above average = " + studentsAboveAvg);
sc.close();
}
}