write an application that prompts the user for two integers and then prompts the
ID: 3647375 • Letter: W
Question
write an application that prompts the user for two integers and then prompts the user to enter an option as follows: 1 to add the two integers, 2 to subtract the second integer from the first, 3 to multiply the integers. and 4 to divide the first integer by the second. Display an error message if the user enters an option other than 1 through 4 or if the user chooses the divide option but enters 0 for the second integer. Otherwise, display the results of the arithmetic.Explanation / Answer
import java.util.*; public class NumberExample{ public static void main(String[]args){ int sum=0,sumSquares=0; int num1=0,num2=0; Scanner input=new Scanner(System.in); System.out.print("Enter First Number: "); num1=input.nextInt(); System.out.print("Enter Second Number: "); num2=input.nextInt(); if(num1>num2){ System.out.print("Your First Number is greater than second.So Please re-enter: "); num1=input.nextInt(); } else{ System.out.println("Odd Numbers: "); while(num1Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.