i want to read inside a for loop two variables with scanner class then save them in a collection Map code is below :
public class Example{
public static void main(String args[]){
Map<String,Integer> mapSub = new HashMap<String,Integer>();
for (int i=0;i<nbSubnet;i++){
System.out.println("Enter name of the subnet "+i+" : ");
String nameSubnet = scanner.nextLine();
System.out.println("Enter the size of the subnet "+i+" : ");
int sizeSubnet = scanner.nextInt();
mapSub.put(nameSubnet, sizeSubnet);
}
}
}
but i get this exeption after running the code :
Enter name of the subnet 0 :
Enter the size of the subnet 0 :
IT
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at view.Main.main(Main.java:60)
any help would be great thanks