import java.util.Scanner;
public class NumberWord {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
String word = x.nextLine();
int number = x.nextInt();
System.out.println(number + ","+" " + word);
}
}
我想编写一个程序,该程序从控制台读取一个字符串和一个整数,然后输出该整数,后跟一个逗号,一个空格,然后是该字符串。例如,如果输入为Wow
和10
,则您的输出应为10, Wow
。
答案 0 :(得分:0)
好的..这是我的代码,是从您的代码中复制的。.
public class NumberWord {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
String word = x.nextLine();
int number = x.nextInt();
System.out.println(number + "," + " " + word);
}
}
这里是输出。这不是预期的吗?
IMP::由于您使用的是nextLine,因此请确保在插入Enter
之后也依次在Wow
之后按下10
。