• 【自动化__持续集成】___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);
     }
    
  • 相关阅读:
    jQuery入门教程
    vue-lazyload 图片不更新
    Eggjs 设置跨域请求
    Vue.js错误: Maximum call stack size exceeded
    ubuntu nginx ssl 证书配置
    ubuntu 安装nginx, 出现 Unable to locate package
    nginx 判断移动端或者PC端 进入不同域名
    node.js 生成二维码
    Linux 配置ssh 免密码登录
    nodejs 从部署到域名访问
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7487217.html
Copyright © 2020-2023  润新知