在java中怎么用循环实现:“输入某年某月某日,判断这一天是这一年的第几天?” 输入判断什么的就不做了 import java.util.Scanner;public class test2 { public static void main(String[]args){ Scanner s=new Scanner(System.in);int year,month,day;int allDay;int[]days1={31,28,31,30,31,30,31,31,30,31,30,31};int[]days2={31,29,31,30,31,30,31,31,30,31,30,31};while(true){ allDay=0;year=0;month=0;day=0;System.out.println(\"请输入年份\");year=s.nextInt();System.out.println(\"请输入月份\");month=s.nextInt();System.out.println(\"请输入日期\");day=s.nextInt();if((year%4=0&year%100。0)|year%400=0){ for(int i=0;i;i+)allDay+days2[i];} else { for(int i=0;i;i+)allDay+days1[i];} allDay+day;System.out.println(\"这一天是这一年的第\"+allDay+\"天\");} } }
用java编写 输入某年某月某日,判断这一天是星期几 import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Calendar;public class CCC {public static void main(String[]args)throws IOException {System.out.println(\"请输入2113年月日,格式:yyyy-MM-dd\");BufferedReader br=new BufferedReader(new InputStreamReader(System.in));String s=br.readLine();Calendar c=Calendar.getInstance(java.util.Locale.CHINA);String[]sp=s.split(\"-\");c.set(Calendar.YEAR,Integer.parseInt(sp[0]));c.set(Calendar.MONTH,Integer.parseInt(sp[1])-1);c.set(Calendar.DATE,Integer.parseInt(sp[2]));int wd=c.get(Calendar.DAY_OF_WEEK);String x=\";switch(wd){case 1:x=\"星期日5261;break;case 2:x=\"星期一;break;case 3:x=\"星期二;break;case 4:x=\"星期三4102;break;case 5:x=\"星期四;break;case 6:x=\"星期五;break;case 7:x=\"星期六1653;break;}System.out.println(s+\"是:\"+x);}}
java如何编译输入某年某月某日输出星期几? import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.Scanner;public class Test1 {public static void main(String[]agrs){Scanner scan=new Scanner(System.in);System.out.println(\"请输入5261一个日期,格式为yyyy-MM-dd(如:2017-12-12)\");String d=scan.nextLine();SimpleDateFormat sdf=new SimpleDateFormat(\"yyyy-MM-dd\");Date date=null;try {date=sdf.parse(d);System.out.println(getWeekOfDate(date));} catch(ParseException e){System.out.println(\"日期格式不正确!4102\");}}public static String getWeekOfDate(Date dt){String[]weekDays={\"星期1653日\",\"星期一\",\"星期二\",\"星期三\",\"星期四\",\"星期五\",\"星期六\"};Calendar cal=Calendar.getInstance();cal.setTime(dt);int w=cal.get(Calendar.DAY_OF_WEEK)-1;if(w)w=0;return weekDays[w];}}测试没问题