If a marks obtained by a student in 5 different subject are input through the keyboard. Find out the total marks and percentage obtained by a student
—————————————
import java.util.Scanner;
public class StudentMarks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Array to store marks of 5 subjects
int[] marks = new int[5];
int total = 0;
System.out.println(“Enter marks for 5 subjects:”);
// Input marks and calculate total
for (int i = 0; i < 5; i++) {
System.out.print(“Subject ” + (i + 1) + “: “);
marks[i] = sc.nextInt();
total += marks[i];
}
// Calculate percentage
double percentage = (double) total / 5;
// Display results
System.out.println(“\nTotal Marks = ” + total);
System.out.println(“Percentage = ” + percentage + “%”);
sc.close();
}
}
OUTPUT
Enter marks for 5 subjects:
Subject 1: 78
Subject 2: 85
Subject 3: 90
Subject 4: 76
Subject 5: 80
Total Marks = 409
Percentage = 81.8%