Java实现输入数字1-7出现相应的英文星期几代码
4个回答
展开全部
public String getXqEn(int xqNum){
Map<Integer,String> xqMap = new HashMap<Integer,String>();
xqMap.put(1,"星期一");
xqMap.put(2,"星期二");
xqMap.put(3,"星期三");
xqMap.put(4,"星期四");
xqMap.put(5,"星期五");
xqMap.put(6,"星期六");
xqMap.put(7,"星期七");
String xqEn = xqMap.get(xqNum);
System.out.print(xqEn );
return xqEn;
}
把星期翻译成英文就可以了!
展开全部
import java.util.Scanner;
public class AAA {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入1-7:");
int i = -1;
do{
i = scan.nextInt();
String[] weekend = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
System.out.println(weekend[i-1]);
}while(i<=7&&i>=1);
}
最最简单的例子,很多漏洞,仅供学习使用。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
写一个数组,通过数字星期索引得到英文
追问
可以帮忙写一下代码么,谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String [] week = new String []{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
Scanner x = new Scanner(System.in);
System.out.println("请输入1-7的数字");
int weeked = x.nextInt();
for (int i = 0; i < week.length; i++) {
if(weeked == (i+1)){
System.out.println(week[i]);
}
}
Scanner x = new Scanner(System.in);
System.out.println("请输入1-7的数字");
int weeked = x.nextInt();
for (int i = 0; i < week.length; i++) {
if(weeked == (i+1)){
System.out.println(week[i]);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询