Hallo,
ich habe festgestellt, dass "nextLine" bei Übergang von "next" , "nextInt" ,... keine Eingabe abfragt, sondern nichts zurückgibt.
Ausgabe:
Ich komme nicht zum Eingeben von s4 nach der Ausgabe von >3<.
Nun ist die Frage, warum das so ist.
Hat jemand von euch eine Idee?
ich habe festgestellt, dass "nextLine" bei Übergang von "next" , "nextInt" ,... keine Eingabe abfragt, sondern nichts zurückgibt.
Code:
// package VerknuepfungVonObjekten;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner inputSc = new Scanner (System.in);
int st1= inputSc.nextInt();
System.out.print(">" + st1 + "<");
int st2= inputSc.nextInt();
System.out.print(">" + st2 + "<");
int st3= inputSc.nextInt();
System.out.print(">" + st3 + "<");
String st4= inputSc.nextLine();
System.out.print(">" + st4 + "<");
String st5= inputSc.nextLine();
System.out.print(">" + st5 + "<");
String st6= inputSc.nextLine();
System.out.print(">" + st6 + "<");
String st7= inputSc.nextLine();
System.out.print(">" + st7 + "<");
String st8= inputSc.nextLine();
System.out.print(">" + st8 + "<");
}
}
Code:
1
>1<2
>2<3
>3<><s4
>s4<s5
>s5<s6
>s6<s7
>s7<BUILD SUCCESSFUL (total time: 18 seconds)
Nun ist die Frage, warum das so ist.
Hat jemand von euch eine Idee?