62,628
社区成员
发帖
与我相关
我的任务
分享import java.util.Date;
import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class MyDate{
public static final String [] MONTH = new String []{
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
public static int getMonth(String month){
for(int i = 1; i < 13; i++){
if(MONTH[i].equals(month)){
return i;
}
}
return -1;
}
}
public class TestDemo{
public static void main(String [] args) throws ParseException{
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
int temp = cin.nextInt();
String day;
if(temp < 10){
day = "0" + temp;
}
else{
day = "" + temp;
}
String month;
temp = MyDate.getMonth(cin.next());
if( temp < 10){
month = "0" + temp;
}
else{
month = temp + "";
}
String year = cin.next();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
System.out.println(year + month + day);
Date date = sdf.parse(year + month + day);
System.out.println(date);
String [] word = date.toString().split(" ");
if("Mon".equals(word[0])){
System.out.println("Monday");
}
if("Tue".equals(word[0])){
System.out.println("Tuesday");
}
if("Wed".equals(word[0])){
System.out.println("Wednesday");
}
if("Thu".equals(word[0])){
System.out.println("Thursday");
}
if("Fri".equals(word[0])){
System.out.println("Friday");
}
if("Sat".equals(word[0])){
System.out.println("Saturday");
}
if("Sun".equals(word[0])){
System.out.println("Sunday");
}
}
}
}import java.util.Date;
import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class MyDate{
public static final String [] MONTH = new String []{
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
public static int getMonth(String month){
for(int i = 1; i < 13; i++){
if(MONTH[i].equals(month)){
return i;
}
}
return -1;
}
}
public class TestDemo{
public static void main(String [] args) throws ParseException{
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
int temp = cin.nextInt();
String day;
if(temp < 10){
day = "0" + temp;
}
else{
day = "" + temp;
}
String month;
temp = MyDate.getMonth(cin.next());
if( temp < 10){
month = "0" + temp;
}
else{
month = temp + "";
}
String year = cin.next();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date = sdf.parse(year + month + day);
String [] word = date.toString().split(" ");
if("Mon".equals(word[0])){
System.out.println("Monday");
}
if("Tue".equals(word[0])){
System.out.println("Tuesday");
}
if("Wed".equals(word[0])){
System.out.println("Wednesday");
}
if("Thu".equals(word[0])){
System.out.println("Thursday");
}
if("Fri".equals(word[0])){
System.out.println("Friday");
}
if("Sat".equals(word[0])){
System.out.println("Saturday");
}
if("Sun".equals(word[0])){
System.out.println("Sunday");
}
}
}
}
不好意思,之前调试忘了删掉多余的输出信息了,只输出星期时,结果还是Wrong Answer.实在是找不出问题在哪,测试过很多数据,结果都是正确的,可是提交之后就是不能AC
你看你写了多少个out.. 