import java.util.Scanner;
public class Demo5_Array {
public static void main(String[] args) {
//System.out.println("星期" + getWeek(7));
Scanner sc = new Scanner(System.in);
System.out.println("请输入星期的范围 1-7");
int week = sc.nextInt();
System.out.println("星期" + getWeek(week));
}
/*
* 根据索引返回对应得星期
* 1,返回值类型char
* 2,参数列表int week
*/
public static char getWeek(int week) {
//定义一个星期表
char[] arr ={' ','一','二','三','四','五','六','日'};
return arr[week]; //通过索引获取表中的元素
}
}
|