Answer to Question #246423 in Java | JSP | JSF for Nguu

Question #246423

Create a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether 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-04T07:51:26-0400
import java.util.Scanner;


public class DoWhile {


	public static void main(String[] args) {
		int condition = 0;
		Scanner scan = new Scanner(System.in);
		do {


			int firstNumber = 0;
			int secondNumber = 0;
			int sumOfNumbers = 0;
			System.out.println("Please provide first numbler and press Enter: ");
			firstNumber = scan.nextInt();
			System.out.println("Please provide second numbler and press Enter: ");
			secondNumber = scan.nextInt();
			sumOfNumbers = firstNumber + secondNumber;
			System.out.println("Sum of entered numbers: " + sumOfNumbers);
			System.out.println("Wont try again?Yes- press 1 or no-press 2 and press Enter: ");
			condition = scan.nextInt();
		} while (condition != 2);
		scan.close();
	}
}

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