java 20

练习一:
package com.shhfg.ds;

public class jave {
    public static void main(String[] args) {
        //麻婆豆腐,北京烤鸭,兰州拉面,北京炸酱面
        //1.定义变量记录我心里想吃的食物
        String food="北京烤鸭";

        //2.拿着这些食物利用switch跟四样食物匹配
        switch (food){
            case "麻婆豆腐":
                System.out.println("吃麻婆豆腐");
                break;
            case "北京烤鸭":
                System.out.println("吃北京烤鸭");
                break;
            case "兰州拉面":
                System.out.println("吃兰州拉面");
                break;
            case "北京炸酱面":
                System.out.println("吃北京炸酱面");
                break;
            default:
                System.out.println("吃稀饭");
        }
    }
}

练习二:

package com.shhfg.ds;

import java.util.Scanner;

public class HelloWorld02 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入这个星期:");
        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("爬山");
                break;
            default:
                System.out.println("没有这个星期哦");
        }
    }
}

你可能感兴趣的:(java)