What will be the final output of the following code snippet when a user enters input values in the order 10, 20, 30, 40, 50, and -1? public static void main(String[] args)
{
Double sum = 0;
Int count = 0;
Double salary = 0;
Double average = 0;
Scanner reader = new Scanner(System.in) ;
System.out.println("Enter salaries (-1 to stop) : ") ;
While (salary != -1)
{
Salary = reader.nextInt() ;
If (salary != -1)
{
Sum = sum + salary;
Count++;
}
}
If (count > 0)
{
Average = sum / count;
System.out.println("The Average Salary: " + average) ;
}
Else
{
System.out.println ("No data!") ;
}
Return 0;
}
A) The Average Salary: 0
B) The Average Salary: 30
C) The Average Salary: 24.83333
D) There will be no output as the code snippet will not compile.
Correct Answer:
Verified
Q62: Which of the following statements is correct
Q85: Which of the following loop(s) should be
Q86: Suppose that a program asks a user
Q87: What will be the output of the
Q88: Which statement is correct about the execution
Q89: How do you fix this code snippet
Q91: When will the loop in the following
Q92: What is the outcome of the following
Q93: What is the sentinel value in the
Q95: What is the last output line of
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents