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
Q3: How many times does the code snippet
Q10: What is the output of the code
Q12: What is the output of the code
Q15: What is the output of the code
Q32: What is the data type of the
Q38: What will be the output of the
Q40: What is the outcome of the following
Q77: What is the output of the code
Q84: Which of the following loops executes exactly
Q101: In the following code snippet, when does
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