My Java Code :
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
static int fun1(double rat[] , double b){
int c = 0;
for(int i=0;i<5;i++){
if(rat[i]>=b)
c++;
}
return c;
}
static int fun2( String loc[] ,int est[], String b){
int c=0,mn=100005,st=-1;
for(int i=0;i<5;i++){
if(loc[i].equals(b) && est[i]<mn)
mn=est[i];
}
for(int i=0;i<5;i++){
if(loc[i].equals(b) && est[i]<mn){
mn=est[i];
st = i;
}
}
return st;
}
public static void main(String args[]){
int id[] = new int[5] ;
String name[] = new String[5];
String loc[] = new String[5];
int est[] = new int[5];
double rat[] = new double[5];
boolean rc[] = new boolean[5];
Scanner sc = new Scanner(System.in);
int i=0;
while(i<5){
id[i] = sc.nextInt();
name[i] = sc.nextLine();
loc[i] = sc.nextLine();
est[i] = sc.nextInt();
rat[i] = sc.nextDouble();
rc[i] = sc.nextBoolean();
i++;
}
String loca = sc.nextLine();
double rate = sc.nextDouble();
int bb = fun1(rat,rate);
if(bb==0)
System.out.println("No such Museums");
else
System.out.println(bb);
int l = fun2(loc,est,loca);
if(l==-1){
System.out.println("No matching museum");
}
else{
System.out.println(name[l]);
System.out.println(est[l]);
}
}
}
My code gives this error , I tried my best but I am unable to resolve this error
I tried using scanner.hasNext() but it gives InputMisMatch Exception.
Even if I consume new line left over using scanner.nextLine() , it still gives error as InputMisMatch Exception.
My input for the code :
211
NRM
delhi
1977
4.4
False
456
national museum
delhi
1949
4.6
True
123
government museum
chennai
1851
4.3
True
055
SJM
hyderabad
1951
4.4
True
065
NCM
delhi
1956
4.5
True
delhi
4.5