Question: instead of using - 1 as sentinel , use Yes or No to continue with grades : import java.util.Scanner; public class Loops { public static

instead of using -1 as sentinel, use Yes or No to continue with grades : import java.util.Scanner;
public class Loops {
public static void main(String[] args){
// TODO Auto-generated method stub
//participation problem for week 3
//instead of using -1 as sentinel
//use yes or no to continue with grades
int numStudents =0;
System.out.println("Please enter the grade of the first student: ");
Scanner inp = new Scanner( System.in);
double grade = inp.nextDouble();
double sumGrades =0.0;
while( grade !=-1){
sumGrades += grade;
numStudents++;
System.out.println("Keep entering grades when you are done enter -1");
System.out.println("Please enter the grade of the next student: ");
inp = new Scanner( System.in);
grade = inp.nextDouble();
}
if( numStudents !=0)
{
double average = sumGrades/numStudents;
System.out.println( "Average grade of "+ numStudents +" students is "+ average);
}
else
System.out.println("Number of students is zero and cannot calculate an average.");
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!