java 从键盘输入一位整数,当输入1-7时,显示下面对应的英文字母星期几的名称

输入其它数字时提示用户重新输入,以数字0结束,求参考
2024-10-31 16:52:45
推荐回答(2个)
回答1:

package pac;

import java.util.Scanner;

public class FirstJava {

//Sunday, Monday, Tuesday,
//Wednesday, Thursday, Friday, Saturday,
public static String wk[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// display :This is my first program
System.out.println("This is my first program!");
week();
}

public static int week()
{
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
if(i==0) return 0;
else if(i<0||i>7) week();
else System.out.println(wk[i-1]);
return 1;

}

回答2:

百度 一下 就有