Answer to Question #253804 in Java | JSP | JSF for Mike

Question #253804

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


1
Expert's answer
2021-10-19T15:38:48-0400


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");
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS