Analysis of examination results using nested control statements In Java

The Java class that implements the pseudocode algorithm and two sample executions are shown in Fig. 4.12. Lines 13, 14, 15 and 22 of main declare the variables that are used to process the examination results.

Formulating Algorithms: Nested Control Statements

/*
 *       Filename:  Analysis.java
 *
 *    Description:  Fig. 4.12 - Analysis of examination results using nested control
 *                  statements
*  @Author:  Bilal Tahir Khan Meo
 *  Website: https://www.codeblah.com
 *
 * =====================================================================================
 */
import java.util.Scanner;

public class Analysis{
    public static void main(String[] args){
        int passes = 0;
        int failures = 0;
        int studentCounter = 1;
        int result;

        Scanner sc = new Scanner(System.in);

        // process 10 students using counter controlled loop
        while(studentCounter <= 10){
            System.out.print("Enter result (1 = pass, 2 = fail): ");
            result = sc.nextInt();

            if(result == 1)
                passes++;
            else
                failures++;

            studentCounter++;
        }

        System.out.printf("Passed: %d\nFailed: %d\n", passes, failures);

        if(passes > 8)
            System.out.println("Bonus to instructor!");
    }
}

Output of Program

Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 2
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Passed: 9
Failed: 1
Bonus to instructor!

Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 2
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 2
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 2
Enter result (1 = pass, 2 = fail): 2
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Enter result (1 = pass, 2 = fail): 1
Passed: 6
Failed: 4