- /*
- 需求:键盘输入1-7的数字,返回对应星期的英文单词。
- 思路:
- A:调用Scanner类实现键盘录入数据的操作;
- B:创建字符串数组,顺序存储一周七天的英文单词;
- C:返回键盘录入数据对应索引的字符串元素值。
- */
- import java.util.Scanner;
- class ReturnWeek {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入1-7的整数:");
- int num = sc.nextInt();
- String[] week = {"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
- if (num>7 || num<1) {
- System.out.println("数字输入有误");
- }
- else {
- System.out.println("一周的第"+num+"天是"+week[num]);
- }
- }
- }
复制代码
|
|