刚开始看视屏,学老毕的,自己敲代码- class Demo2_18_1
- {
- public static void main(String[] args)
- {
- int x=5;
- if(x>7||x<1)
- System.out.println("该数字不属于1-7之间");
- else if(x==1)
- System.out.println(x+"Monday");
- else if(x==2)
- System.out.println(x+"Thusday");
- else if(x==3)
- System.out.println(x+"Wedesday");
- else if(x==4)
- System.out.println(x+"Tursday");
- else if(x==5)
- System.out.println(x+"Friday");
- else if(x==6)
- System.out.println(x+"Saturday");
- else
- System.out.println(x+"sunday");
- }
- }
复制代码
看到第四天的内容,想到了领着一种方法,用数组进行存储- class Demo
- {
- public static void main(String[] args)
- {
- int a=9;
- if (a<1||a>7)
- System.out.print("输入错误");
- else
- {
- for (int x=1; x<8; x++)
- {
- String[] arr={"周一","周二","周三","周四","周五","周六","周日"};
- System.out.print((a==x)?(String)arr[x-1]:"");
- }
- }
- }
- }
复制代码
|