public String getXqEn(int xqNum){
MapxqMap = new HashMap ();
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]);
}
}