数组查表法之根据键盘录入索引,查找对应星期

根据键盘录入索引,查找对应星期:

import java.util.Scanner;
class Hello2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个1-7之间的整数");
        int week = sc.nextInt();
        System.out.println("星期" + getWeek(week));
        
    }
    public static char getWeek(int week) {
        char[] arr = {' ','一','二','三','四','五','六','日'};
        return arr[week];
    }

}

结果:

 

猜你喜欢

转载自www.cnblogs.com/Wangzui1127/p/11185350.html
0条评论
添加一条新回复