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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started