Question: Given the code below, suppose the user enters the sequence: - 8 4 3 - 2 7 1 5 - 1 3 2 4 .

Given the code below, suppose the user enters the sequence: -843-2715-1324. What will be displayed to the console?
Scanner input = new Scanner(System.in);
int num =0, sum =0;
System.out.print("Enter sequence of numbers (enter -1 to finish): ");
do {
if(num >0)
sum += num;
num = input.nextInt();
} while (num !=-1);
System.out.print(sum);
input.close();

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 Programming Questions!