Question: Exception erro when use while loop and sc.close() at same time. But can be run, if delete one of them import java.util.*; public class Hw4_Chenglin_Nie
Exception erro when use while loop and sc.close() at same time. But can be run, if delete one of them
import java.util.*;
public class Hw4_Chenglin_Nie {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
int[] arrNum = new int[5];
for(int i = 0; i
System.out.print("Enter a integer "+(i+1)+":");
arrNum[i] = sc.nextInt();
}
int min = arrNum[0],max = arrNum[0],diff = 0;
for(int tempNum: arrNum){
min = Math.min(min,tempNum);
max = Math.max(max,tempNum);
}
diff = max - min;
System.out.printf("%nMax number: %1$d %nMin number : %2$d %nDifference : %3$d %n%n",
max,min,diff);
}
sc.close();
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unreachable code


public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true){ int[] arrNum = new int[5]; for(int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
