java 中的串联未按预期工作

concatenation not working as expected in java

当我输入 "little code" 作为输入(在最后一行)时,我期望输出 "I wrote a little code"(在最后一行),但输出是 "I wrote a " 这是我的代码:`

String s = "I wrote a ";
int i = 4;
double j = 7.0; 
Scanner scan = new Scanner(System.in);
String c; int a; double b;
a = scan.nextInt();
b = scan.nextDouble();
c = scan.nextLine();
System.out.println(i + a);
System.out.println(j + b);
System.out.println(s + c);
scan.close();

这段代码对我来说工作正常:

String s = "I wrote a ";
int i = 4;
double j = 7.0; 
Scanner scan = new Scanner(System.in);
String c; int a; double b;
a = scan.nextInt();
b = scan.nextDouble();
scan.nextLine();
c = scan.nextLine();
System.out.println(i + a);
System.out.println(j + b);
System.out.println(s + c);
scan.close();

只是在 b = scan.nextDouble();

之后缺少 scan.nextLine()