在while循环里面加一句,获取一行输入到enter就可以了。
package While
import java.util.Scanner;
public class Whiledo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("是否继续打印(按Enter继续打印)");
String enter = sc.nextLine();
while(enter.length()==0) {
System.out.println("已打印!");
enter = sc.nextLine();
}
}
}