zoukankan      html  css  js  c++  java
  • 【自动化__持续集成】___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);
     }
    
  • 相关阅读:
    单例模式
    建造者模式
    工厂方法模式
    原型模式
    适配器模式
    桥接模式
    装饰模式
    组合模式
    多线程的学习与GDI的学习
    我们复习.Net的这些日子里
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7487217.html
Copyright © 2011-2022 走看看