Java program to accept five subjects marks from student and print total and percentage on the output screen

EX: Write a java program to accept five subjects marks from student and print total and percentage on the output screen. How to write a java program to accept five subjects marks and print total and percentage. Java program to accept marks from students and print total and percentage.


Program to print total and percentage:


import java.util.Scanner;

public class StudentGrade {

    public static void main(String[] args){

        int s1,s2,s3,s4,s5;
        int total;
        float per;

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the five subjects marks: ");
        s1 = sc.nextInt();
        s2 = sc.nextInt();
        s3 = sc.nextInt();
        s4 = sc.nextInt();
        s5 = sc.nextInt();

        total = s1+s2+s3+s4+s5;
        per = total/5;

        System.out.println("Total = "+total);
        System.out.println("percentage = "+per);

    }

}

Above java program will show the following Output:

Enter the five subjects marks: 85
97
96
89
99
Total = 466
percentage = 93.0

No comments:

Post a Comment

If you have any doubts, please discuss here...👇