Question
[Inst. 4.2] Use the below mentioned code for following question(s). Scanner keyboard = new Scanner(System.in); int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades
[Inst. 4.2] Use the below mentioned code for following question(s).
Scanner keyboard = new Scanner(System.in);
int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. If there are 8 students and they have taken 8, 10, 5, 3, 7, 11, 12, and 9 tests respectively, how many times will the inner loop execute for all students?
A. | 8 |
B. | 57 |
C. | 65 |
D. | Cannot tell |
[Inst. 4.2] Use the below mentioned code for following question(s).
Scanner keyboard = new Scanner(System.in);
int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. If there are 5 students and each student has 10 grades, how many times will the inner loop execute for each student?
A. |
[Inst. 4.2] Use the below mentioned code for following question(s). Scanner keyboard = new Scanner(System.in); int studentID, studentCount = 0, studentGrade, numberOfStudentGrades = 0, totalOfGrades = 0; int totalOfStudentGrades = 0, totalNumberOfGrades = 0; double studentAverage, classAverage; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); while (studentID != 0){ studentCount++; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); while(studentGrade != -1) { numberOfStudentGrades++; totalOfStudentGrades += studentGrade; System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); } if (numberOfStudentGrades > 0) { studentAverage = (double)totalOfStudentGrades/numberOfStudentGrades; System.out.println("Student " + studentID + "average is " + studentAverage); totalNumberOfGrades += numberOfStudentGrades; totalOfGrades += totalOfStudentGrades; } numberOfStudentGrades = 0; totalOfStudentGrades = 0; System.out.println("Enter student ID: "); studentID = keyboard.nextInt(); } if (totalNumberOfGrades != 0) System.out.println("Average of all grades is " + (totalOfGrades/totalNumberOfGrades)); Refer to Inst. 4.2. If 10 students are entered and each student has 12 grades, how many times does the outer loop execute?
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started