import java.util.Scanner;public class Test
{
public static void main(String[] args)
{
System.out.print("What is your phrase?");
Scanner s1 = new Scanner(System.in);
System.out.print("How many times should I repeat it?");
Scanner s2 = new Scanner(System.in); for(int i=1; i <= s2.nextInt(); i++)
{
System.out.println(s1.next());
}
}
}我本意是想让程序提示“What is your phrase?”,然后我在后面输入比如my name is Jack,然后程序再出现提示“How many times should I repeat it?”,然后我在后面输入比如数字3,然后得到重复输出的2次my name is Jack.可是程序不是按照我的想法运行的啊,应该怎么调整呢?请求指教
{
public static void main(String[] args)
{
System.out.print("What is your phrase?");
Scanner s1 = new Scanner(System.in);
System.out.print("How many times should I repeat it?");
Scanner s2 = new Scanner(System.in); for(int i=1; i <= s2.nextInt(); i++)
{
System.out.println(s1.next());
}
}
}我本意是想让程序提示“What is your phrase?”,然后我在后面输入比如my name is Jack,然后程序再出现提示“How many times should I repeat it?”,然后我在后面输入比如数字3,然后得到重复输出的2次my name is Jack.可是程序不是按照我的想法运行的啊,应该怎么调整呢?请求指教
import java.util.Scanner;public class Test {
public static void main(String[] args) {
System.out.println("What is your phrase?");
Scanner s1 = new Scanner(System.in);
String str1 = s1.next(); System.out.println("How many times should I repeat it?");
Scanner s2 = new Scanner(System.in);
int num = s2.nextInt(); for (int i = 1; i <= num; i++) {
System.out.println(str1);
} }}
{
System.out.println(s1.next());//s1.next()指的下一个输入,怎么有值呢?
}