Question: import java.util.Scanner; public class DoSum { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System .

import java.util.Scanner;
public class DoSum
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int previous;
int sum =0;
int x =0;
do
{
System.out.print("Enter an integer (0 to stop): ");
int current = in.nextInt();
if (current == previous){
break; // Break the loop if the same value is read twice in a row
}
sum += current;
previous = current;
} while (previous !=0);
System.out.println("Sum: "+ sum);
}
}

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!