【发布时间】:2026-01-30 16:55:01
【问题描述】:
以下是 Java 程序的预期输出。
Hello. What is your name?
Hi John! How old are you?
So you're 22 eh? That's not old at all!
How much do you make John?
500.0! I hope that's per hour and not per year! LOL!
预期输入:
John 22 500(我需要水平输入,而不是垂直输入)。
那么我需要进行哪些更改?像任何函数一样 scanner.next() 而不是 nextLine() 应该使用或如何使用?
你能告诉我程序有什么问题吗?
public class Test2 {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
Scanner in = new Scanner(System.in);
Scanner inc = new Scanner(System.in);
String xyz = scanner.nextLine();
int age = in.nextInt();
double cme = inc.nextInt();
System.out.println("Hello.What is your name?");
System.out.println("So you're "+age+"eh?That's not old at all!" );
System.out.println("hi"+xyz+"!How old are you?");
System.out.println("How much do you make"+xyz+"?");
System.out.println(+cme+"!I hope that's per hour and not per year!LOL!");
}
}
【问题讨论】: