目录
1.顺序输出实现
//顺序输出编写一个二级菜单 public class caidan01{ public static void main(String[] args){ System.out.println("一级示例1"); System.out.println("\t二级示例1"); System.out.println("\t二级示例2"); System.out.println("\t二级示例3"); System.out.println("\t二级示例4"); System.out.println("一级示例2"); System.out.println("\t二级示例1"); System.out.println("\t二级示例2"); System.out.println("\t二级示例3"); System.out.println("\t二级示例4"); System.out.println("一级示例3"); System.out.println("\t二级示例1"); System.out.println("\t二级示例2"); System.out.println("\t二级示例3"); System.out.println("\t二级示例4"); } }
运行结果:
2.循环输出实现
while循环实现
/* while循环编写一个二级菜单: */ public class caidan01{ public static void main(String[] args){ int i=1; while(i<7){ System.out.println("一级示例"+i); i++; int j=1; while(j<5){ System.out.println("\t二级示例"+j); j++; } } } }
运行结果
do...while...循环实现
/* do...while循环编写一个二级菜单: */ public class caidan03{ public static void main(String[] args){ int i=1; do{ System.out.println("一级示例"+i); i++; int j=1; do{ System.out.println("\t二级示例"+j); j++; }while(j<5); }while(i<7); } }
运行结果:
for循环实现
/* for循环编写一个二级菜单: */ public class caidan02{ public static void main(String[] args){ for(int i=1;i<7;i++){ System.out.println("一级示例"+i); for(int j=1;j<5;j++){ System.out.println("\t二级示例"+j); } } } }
运行结果: