package day5;
/*
用一个数组,保存星期一到星期天的7个英语单词
从键盘输入1-7,显示对于单词 利用数组的下标访问
*/
public class shuzu3
{
public static void main(String[] args)
{
String[] weeks = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
//从键盘上输入
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("请输入星期(1-7):");
int week = input.nextInt();
//差错判断
if(week>7 || week<1)
System.out.println("输入有误!");
else
System.out.println(week+"对应的星期的单词是:"+ weeks[week-1]);
}
}
11.数组练习
最新推荐文章于 2024-01-05 13:09:35 发布