Weyu‘s blog

  • 首页
  • 代码
  • 作品
  • 学习
  • 折腾
  • 随笔
  • 关于博主
  • 时光映像
  • 我的网盘
  • 文章归档
  • 友情链接

Day3 笔记 选择结构Switch语句的练习

  • admin
  • 2017-02-18
  • 0
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 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);






	}
}
© 2025 Weyu‘s blog
  • {{ item.name }}
  • {{ item.name }}