Try the fastest way to create flashcards
Question

# Suppose the input is 2 3 4 5 0. What is the output of the following code? import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number, sum = 0, count; for (count = 0; count < 5; count++) { number = input.nextInt(); sum += number; } System.out.println("sum is " + sum); System.out.println("count is " + count); } }

Solution

Verified
Step 1
1 of 2
Output:
sum is 14
count is 5


We have five iterations where the control variable’s value is increased four times since the initialization (0 1 2 3 4) until the condition becomes false.

During those iterations, user inputs (2 3 4 5 0) are summed and the value of the sum variable is 14.

## Recommended textbook solutions #### Introduction to Java Programming, Brief

8th EditionISBN: 9780132130790 (1 more)Y. Daniel Liang
500 solutions #### Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions #### Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions #### Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions