+ 2
Why it show thread in main exception when i use Scanner but if i not den its working so plz suggest me on ths!!!
https://code.sololearn.com/c7oeoqe0qkgW/?ref=app Donna [A^dr3w] Gaurav Agrawal Dan Walker Dev
1 Odpowiedź
+ 20
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
String ct[]= new String[5];
int tmp[]= new int[5],a=tmp.length;
for(int i=0;i<ct.length+tmp.length;i++)
{ if(i==0)
System.out.println("Enter the name of "+(i+1)+" city with temperature");
if(i>=0&&i<ct.length)
ct[i]= sc.nextLine();
if(i>=a&&i<tmp.length+a)
tmp[i-a]= sc.nextInt();
}
int max,min;
max= tmp[0];
min= tmp[0];
int pos1=0,pos2=0;
for(int i=0;i<tmp.length;i++)
{
if(max<tmp[i])
{
max= tmp[i];
pos1= i;
}
else if(min>tmp[i])
{
min= tmp[i];
pos2= i;
}
}
System.out.println("City having maximum temperature of "+tmp[pos1]+" is "+ct[pos1]);
System.out.println("City having minimum temprature of "+tmp[pos2]+" is "+ct[pos2]);
}}