编写一个程序,根据用户输入(1~7) 输出英文星期几
3个回答
展开全部
C语言的:
#include<stdio.h>
void main()
{
int num;
while(1)
{
printf("输入1-7\n");
scanf("%d",&num);
while(1)
{
if (1<=num<=7) break;
else printf("重新输入\n");
scanf("%d",&num);
}
switch (num)
{
case 1: printf("monday");break;
case 2: printf("tuesday"); break;
case 3: printf("wednesday");break;
case 4: printf("thursday"); break;
case 5: printf("friday");break;
case 6: printf("saturday"); break;
case 7: printf("sunday"); break;
}
}
}
更多追问追答
追问
这个能做吗?
c语言 求方程 ax的平方+bx=0的解
展开全部
public String getWeek(int weekInt){
if(weekInt==1) return "星期一";
if(weekInt==2) return "星期二";
if(weekInt==3) return "星期三";
//下面依次类推,一直到星期天
return "不是1~7中的数";
}
//上面是一个函数,传入整型的数。当然在用户输入的时候你还要判断是否输入的是数字
if(weekInt==1) return "星期一";
if(weekInt==2) return "星期二";
if(weekInt==3) return "星期三";
//下面依次类推,一直到星期天
return "不是1~7中的数";
}
//上面是一个函数,传入整型的数。当然在用户输入的时候你还要判断是否输入的是数字
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java 语言的
System.out.println("请输入数字1-7,然后回车...");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
switch(num)
{
case 1:
System.out.println(" Today is Monday!");
break;
case 2:
System.out.println("Today is tuesday!");
break;
case 3:
System.out.println("Today is Wensday!");
break;
case 4:
System.out.println("Today is Thursday!");
break;
case 5:
System.out.println("Today is Friday!");
break;
case 6:
System.out.println("Today is Saturday!");
break;
case 7:
System.out.println("Today is Sunday!");
break;
}
System.out.println("请输入数字1-7,然后回车...");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
switch(num)
{
case 1:
System.out.println(" Today is Monday!");
break;
case 2:
System.out.println("Today is tuesday!");
break;
case 3:
System.out.println("Today is Wensday!");
break;
case 4:
System.out.println("Today is Thursday!");
break;
case 5:
System.out.println("Today is Friday!");
break;
case 6:
System.out.println("Today is Saturday!");
break;
case 7:
System.out.println("Today is Sunday!");
break;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询