我正在学习 Java,而且我对它的了解并不多,我不知道为什么,但 Java 似乎跳过了一行。我不认为我所有页面中的代码真的很必要,所以我只放第一页和使用它时得到的结果。谢谢!
import java.util.Scanner;
public class First {
public static void main(String args[]){
Scanner scanz = new Scanner(System.in);
System.out.println("Hello, please tell me your birthday!");
System.out.print("Day: ");
int dayz = scanz.nextInt();
System.out.print("Month: ");
int monthz = scanz.nextInt();
System.out.print("Year: ");
int yearz = scanz.nextInt();
System.out.println("Now, tell me your name!");
System.out.print("Name: ");
String namez = scanz.nextLine();
Time timeObject = new Time(dayz,monthz,yearz);
Second secondObject = new Second(namez,timeObject);
System.out.println("\n\n\n\n\n" + secondObject);
}
}
它跳过了行
String namez = scanz.nextLine();
控制台输出:(请原谅生日,这是其他东西)
Hello, please tell me your birthday!
Day: 34
Month: 234
Year: 43
Now, tell me your name!
Name:
My name is and my birthday is 00/00/43
它没有给你机会给一个名字,它只是直接跳过并将名字作为空。请,如果有人可以,请告诉我为什么!我想学习 Java,而这个小烦恼挡住了我的路。
谢谢!