Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions