Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Ex07 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int y; // grade entered by the user
- int c = 0; // count valid grades
- int sum = 0;
- double avg;
- double max = 0;
- String className;
- int pupilsInClass;
- System.out.print("Enter class name: ");
- className = in.next();
- System.out.print("Enter number of pupils in class " + className + ": ");
- pupilsInClass = in.nextInt();
- for (int i = 0; i < pupilsInClass; i++) {
- // new student
- System.out.println("* * * New Pupil Data * * *");
- c = 0;
- sum = 0;
- // get first grade
- System.out.print("Enter your grade (0 to 100): ");
- y = in.nextInt();
- while (y >= 0 && y <= 100) {
- // valid grade
- c++; // add 1 to the counter
- sum = sum + y; // add grade to sum
- // get next grade
- System.out.print("Enter your grade (0 to 100): ");
- y = in.nextInt();
- }
- System.out.println("You have " + c + " grades");
- System.out.println("The sum of grades is " + sum);
- avg = (double) sum / c;
- System.out.println("The average is " + avg);
- if (avg > max) {
- max = avg;
- }
- }
- System.out.println("max class average is " + max);
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement