【自动化__持续集成】___java___控制结构
一、if和switch语句代码如下
package com.wujianbo; import java.util.Scanner; public class Demo06 { public static void main(String[] args) { // TODO Auto-generated method stub Demo06 demo06= new Demo06(); //demo06.branch(); demo06.execif(); } public void execif(){ Scanner sc= new Scanner(System.in); System.out.println("请输入年龄:"); int age= sc.nextInt(); if (age <= 20) { System.out.println("您好,骚年!"); } else if (age <= 40) { System.out.println("您好,大哥!"); } else if (age <= 60) { System.out.println("您好,大叔!"); } else { System.out.println("您好,大爷!"); } if (age == 45) { System.out.println("您好,强哥!"); } } }
package com.wujianbo; import java.util.Date; import java.util.Scanner; public class Demo06 { public static void main(String[] args) { // TODO Auto-generated method stub Demo06 demo06= new Demo06(); //demo06.branch(); //demo06.execif(); demo06.execcase(); } public void execcase(){ String x=""; int d= new Date().getDate(); System.out.println(d+"a"); switch (d) { case 0: x = "今天是星期一"; break; case 1: x = "今天是星期一"; break; case 2: x = "今天是星期一"; break; case 3: x = "今天是星期一"; break; case 4: x = "今天是星期一"; break; case 5: x = "今天是星期一"; break; case 6: x = "今天是星期一"; break; case 25: x = "今天是星期七"; break; } System.out.println(x); } }
二、for、while、do while的代码如下
public void exeFor(){ int result= 0; //for (int i=1; i<=100; i++) { // result += i; //} int i= 1; for (; i<=100 ;) { result += i; i++; } System.out.println(result); }
public void exeWhile() { int i= 1; int result= 0; while (i<101) { result += i; i++; } System.out.println(result); }
public void exeDowhile() { int i= 1; int result= 0; do { result += i; i++; }while (i<101); System.out.println(result); }