-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasstest.java
More file actions
42 lines (40 loc) · 1.35 KB
/
Copy pathclasstest.java
File metadata and controls
42 lines (40 loc) · 1.35 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
import java.util.Scanner;
import java.util.Arrays;
public class classtest {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
int[] marks = new int[5];
String[] names= new String[5];
int n=5;
for (int i=0;i<n;i++){
System.out.println("Enter student name : ");
names[i]= scan.nextLine();
System.out.println("Enter Marks for student "+names[i]+" : ");
marks[i]=scan.nextInt();
scan.nextLine();
}
//display all student marks
System.out.println("Student Marks :");
for(int i=0;i<n;i++){
System.out.println(names[i]+" : "+marks[i]);
}
//calculating class average
int total=0;
for(int mark:marks){
total+=mark;
}
double average= (double)total/5;
System.out.println("Class Average Marks %.3lf%n"+average);
System.out.println("Enter a student name to check the marks :");
String name = scan.nextLine();
boolean f=false;
for(int i=0;i<n;i++){
if (name.equalsIgnoreCase(names[i])){
System.out.println(names[i]+"Mark is : "+marks[i]);
f=true;break;
}
}
if (!f) System.out.println("Not found ");
scan.close();
}
}