for的死循环的运用
注意:遇到break ;跳出整个for循环
1 package Cforth; 2 3 import java.util.*; 4 5 public class C4_16 { 6 public static void main(String[] args) { 7 Scanner in = new Scanner(System.in); 8 for (;;) { 9 System.out.println("还跑吗"); 10 String flag = in.next(); 11 if (flag.equals("yes") || flag.equals("YES")) { 12 System.out.println("那你继续跑吧"); 13 } else { 14 System.out.println("停止"); 15 break; 16 } 17 } 18 19 } 20 }
测试结果:
测试成功!