Create a do-while loop that ask the user to enter two numbers. The numbers should be added and sum displayed. The loop should ask whether the user he or she wishes to perform the operation again. If so the loop should repeat; otherwise it should terminate
package do_while;
import java.util.Scanner;
public class Do_while {
public static void main(String[] args) {
int choice;
do{
System.out.println("Enter the first number: ");
Scanner scan = new Scanner(System.in);
int first = scan.nextInt();
System.out.println("Enter the second number: ");
int second = scan.nextInt();
System.out.printf("The addition of %d and %d is: %d", first, second, (first+second));
System.out.println("\nEnter 1 to continue or 0 to stop");
choice = scan.nextInt();
}while(choice==1);
System.out.println("Terminated successfully");
}
}
Comments
Leave a comment