ich will sie dann in einer Sammlung Karte Code innerhalb eines for-Schleife zwei Variablen mit Scanner-Klasse zu lesen ist unten sparen:wie kann ich zwei Eingänge in Schleife Java lesen
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);
}
}
}
aber ich bekomme diese Ausnahme nach dem Laufen der 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)
jede Hilfe großer dank
nicht speichern kann, 'Es' ist kein 'int' – Hackerdarshi
i die Zeichenfolge geben„IT“als Name, was ich aus dem Code erwarten die Zeichenfolge zu tun, fragen zuerst und dann fragen Sie nach der Ganzzahl, die die Größe – azdoud
Ich denke, dass dies http://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-for-nextfoo-methods – RubioRic