双重while循环测试代码

来源:互联网 发布:各市平均车流量数据 编辑:程序博客网 时间:2024/06/01 19:40

public class DoubleWhile{
 /*
 循环嵌套:循环的循环体是循环
 */
 public static void main(String[] args){
  //3个富士康的员工,没人需要完成4个零件的组装,但是工厂坏了,只有一个机器能够运转
  int person = 1;
  while(person < 4){
   int part = 1;
   while(part < 5){
    System.out.println("第"+person+"个员工正在做第"+part+"个零件");
    part++;
   }
   person++;
  }
  //打印边长为5的正方形x
  int height = 1;
  while(height < 6){
   int width = 1;
   while(width < 6){
    System.out.print("x ");
    width++;
   }
   System.out.print("\n");
   height++;
  }
 }
}

更多精彩内容请访问:How2J 的 Java教程