gpt4 book ai didi

java - Printf 无法正常工作,不断复制下一行

转载 作者:行者123 更新时间:2023-11-30 01:43:14 25 4
gpt4 key购买 nike

这是我的问题的源代码。 https://pastebin.com/MEwtrxgU .. 在 System.out.printf("按月/日/年输入生日:"); 行中bday[z] = console.next(); 我无法输入生日,因为下一行代码不断插入。

if (choice.equals("s")){
System.out.println("Enter Login Details");
System.out.printf("Enter Username: ");
uname[z] = console.next();
System.out.printf("Enter Password: ");
pword[z] = console.next();
System.out.printf("Enter your Full Name: ");
name[z] = console.next();
System.out.printf("Enter Birthday in Month/Day/Year: ");
bday[z] = console.next();

System.out.printf("Enter Grade for Programming (2 Units): ");
subjects[z][0] = consoleDouble.nextDouble();
System.out.printf("Enter Grade for Computing (3 Units): ");
subjects[z][1] = consoleDouble.nextDouble();
System.out.printf("Enter Grade for UTS (3 Units): ");
subjects[z][2] = consoleDouble.nextDouble();
System.out.printf("Enter Grade for STS (3 Units): ");
subjects[z][3] = consoleDouble.nextDouble();
System.out.printf("Enter Grade for PE (2 Units): ");
subjects[z][4] = consoleDouble.nextDouble();
z++;
}

输出

enter image description here

最佳答案

您在看到错误的行之前输入的问题。如果你想读取几个单词,你还必须放置几个console.next()。官方文件说:

A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.
Method next() finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext() returned true.

希望有帮助。您可以在 oracle 文档网站上查看更多信息。

关于java - Printf 无法正常工作,不断复制下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59207018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com