Question: Convert to if statement ( JAVA ) import java.util.InputMismatchException; import java.util.Scanner; public class Week 3 disc { public static void main ( String [ ]
Convert to if statement JAVA
import java.util.InputMismatchException;
import java.util.Scanner;
public class Weekdisc
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printlnEnter two integers to find their sum.";
Get the first integer
int num getIntegerInputscanner "Enter the first integer: ;
Get the second integer
int num getIntegerInputscanner "Enter the second integer: ;
Calculate and display the sum
int totalSum num num;
System.out.printlnThe sum of num and num is: totalSum;
private static int getIntegerInputScanner scanner, String prompt
while true
try
System.out.printprompt;
return scanner.nextInt;
catch InputMismatchException e
System.out.printlnInvalid input. Please enter a valid integer.";
scanner.nextLine; Clear the input buffer
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
