博客已持续运行3674天
ℛЇℭḰ,我的小窝。
进入博客
不要停下脚步哪怕前方没有光
 
class Demo1_For {
	
	/*
	for(初始化表达式;条件表达式;循环后的操作表达式) {
    循环体;
    }
	


	C执行流程:
	a:执行初始化语句
	b:执行判断条件语句,看其返回值是true还是false
	如果是true,就继续执行
	如果是false,就结束循环
	c:执行循环体语句;
	d:执行循环后的操作表达式
	e:回到B继续。
		*/
	
	public static void main(String[] args) {
		for (int i = 1;i <= 10 ;i++ ) {
			System.out.println("helloworld");
		}
	}
}
 
import java.util.Scanner;
class Test3_SwitchIf {
	public static void main(String[] args) {
		/*Scanner sc = new Scanner(System.in);
		System.out.println("请输入您想查询月份的季节!范围[1-12]");
		/*
		一年有四季
		3,4,5 春季
		6,7,8 夏季
		9,10,11 秋季
		12,1,2 冬季
		
		int x = sc.nextInt();
		switch (x) {
		case 1:
			System.out.println("冬季");
		break;
		case 2:
			System.out.println("冬季");
		break;
		case 3:
			System.out.println("春季");
		break;
		case 4:
			System.out.println("春季");
		break;
		case 5:
			System.out.println("春季");
		break;
		case 6:
			System.out.println("夏季");
		break;
		case 7:
			System.out.println("夏季");
		break;
		case 8:
			System.out.println("夏季");
		break;
		case 9:
			System.out.println("秋季");
		break;
		case 10:
			System.out.println("秋季");
		break;
		case 11:
			System.out.println("秋季");
		break;
		default:
			System.out.println("您输入了范围之外的值!");
		
		}



		=====================================
		再效率些的方法:利用case穿透: 345   678   9 10 11   12 1 2
		
		case 3:
		case 4:
		case 5:
			System.out.println("春季");
		break;
		case 6:
		case 7:
		case 8:
			System.out.println("夏季");
		break;
		=====================================
		*/








		//第二种方式If语句





		Scanner sc = new Scanner(System.in);
		System.out.println("请输入您想查询月份的季节!范围[1-12]");
		int x = sc.nextInt();
		if (x <= 2) {
			System.out.println("冬季");
		}else if (x <= 5 && x >= 3) {
			System.out.println("chunji");
		}else if (x <= 8 && x >= 6) {
			System.out.println("夏季");
		}else if (x <= 9 && x >= 11) {
			System.out.println("秋季");
		}else if (x == 12) {
			System.out.println("冬季");
		}else{
			System.out.println("输入的值不在范围 ");
		}






	/*=================================
	if (x > 12 || x < 1) {
			System.out.println("没有对应的季节");
		}else if (x <= 5 && x >= 3) {
			System.out.println("chunji");
		}else if (x <= 8 && x >= 6) {
			System.out.println("夏季");
		}else if (x <= 9 && x >= 11) {
			System.out.println("秋季");
		}else {
			System.out.println("冬季");
		}
	}
		此方法为老师的方法,代码简洁高效.
		应该膜拜学习
	//=================================*/
	}
}
 
class Test2_Switch {
	public static void main(String[] args) {
			//A,看程序写结果
			/*
			int x = 2;
			int y = 3;
			switch(x){
				default:
					y++;
					break;
				case 3:
					y++;
				case 4:
					y++;
			}
			//y在default处+1变为4
			System.out.println("y="+y);

			*/
			
			//b.看程序写结果
			int x = 2;
			int y = 3;
			switch(x){
				default:
					y++;
				case 3:
					y++;
				case 4:
					y++;
			}
			//因为没有break隔断符,Y加了三次 1 变为 6
			System.out.println("y="+y);






	}
}
 
import java.util.Scanner;
class Test1_Switch {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入明天你想过周几?[数字 1 - 7 ] ... ");
		int week = sc.nextInt();
		switch (week) {
		case 1:
			System.out.println("星期一");
		break;
		case 2:
			System.out.println("星期二");
		break;
		case 3:
			System.out.println("星期三");
		break;
		case 4:
			System.out.println("星期四");
		break;
		case 5:
			System.out.println("星期五");
		break;
		case 6:
			System.out.println("星期六");
		break;
		case 7:
			System.out.println("星期日");
		default:
			System.out.println("输入了错误的值!(1-7)");
		
		}
	}
}
 
class Demo1_Switch {
	public static void main(String[] args) {
		//A:switch语句的格式
		/*
			switch(表达式){				//基本数据类型可以接收byte,short,char,int
				case 值1:				//引用数据类型可以接收枚举(JDK1.5)String(JDK1.7)
					语句体;
					break;
					case值2:
					break;
					...
					default:
					语句体n+1;
					break;
			}

			B:switch语句的格式解释
			c:面试题
			byte可以作为switch的表达式吗?
			long可以作为switch的表达式吗?
			String可以作为switch的表达式吗? 
		
		String name = "Rose";
		String x ="妖";
		switch (x) {
		case "男士":
			System.out.println(name + "是一位" + x + "喜欢吃饭睡觉打Dota");
		break;
		case "女士":
			System.out.println(name + "是一位" + x + "喜欢逛街购物和美容");
		break;
		default:
			System.out.println(name + "是一位"+ x + "依靠雌性激素来维持美貌容颜");
		}
		*/

		String name = "RICK";
		String x = "未知";
		switch (x) {
		case "联通":
			System.out.println("尊敬的玩家您好!根据您的IP地址我们判断您是" + x +"用户!推荐您选择北方大区!" );
		break;
		case "电信":
			System.out.println("尊敬的玩家您好!根据您的IP地址我们判断您是" + x + "用户!推荐您选择南方大区!");
		break;
		case "长城宽带":
			System.out.println("尊敬的玩家您好!根据您的IP地址我们判断您是" + x + "用户!推荐您选择教育网专线!");
		break;
		default:
			System.out.println("很抱歉我们无法识别您的来路地址,请咨询宽带服务商或[荐]使用我们为外网用户开发的V*N搭线工具!");
		}
	}
}
下一页
上一页
回到顶部
Powered by 顾羽宸. Written by . 浙icp备87656888号
在路上...     18.58ms