JavaProgram4

PROGRAM:

To make entry of 5 subjects, restrict to enter more than 100 marks for a subject, use of  for, if, Scanner etc.


import java.util.Scanner;


public class CalculateStudentsResult {

             void mains()
            {
                        int noOfStudents,i,j, sum=0,k, percent;
                        System.out.println("Enter number of students");
                        Scanner s1 = new Scanner(System.in);
                        noOfStudents = s1.nextInt();
                       
                        System.out.println("No of students are = "+noOfStudents);
                       
                        for(i=1; i<= noOfStudents; i++)
                                   
                        {
                                    System.out.println("Enter"+i+"students marks");
                                    System.out.println("________________________");
                                    for(j=1; j<=5;j++)
                                    {
                                                System.out.println("Enter"+j+"subject marks :");
                                                k = s1.nextInt();
                                                sum=sum+k;
                                               
                                               
                                    }
                                    System.out.println("Sum ="+sum);
                                    percent = (sum*100)/500;
                                    System.out.println("Percentage ="+percent);
                                    sum=0;
                                    System.out.println("________________________");
                       
                        }

            }
}


OUTPUT:

Enter number of students
2
No of students are = 2
Enter1students marks
________________________
Enter1subject marks :
65
Enter2subject marks :
85
Enter3subject marks :
45
Enter4subject marks :
21
Enter5subject marks :
90
Sum =306
Percentage =61
________________________
Enter2students marks
________________________
Enter1subject marks :
80
Enter2subject marks :
90
Enter3subject marks :
90
Enter4subject marks :
80
Enter5subject marks :
90
Sum =430
Percentage =86
________________________