import java.util.Arrays;
import java.util.Scanner;
/**
* 根据用户输入的年份,月份,日期计算该日期是一年中的第几天?(switch穿越)
* @author
*
*/
public class Demo6 {
public static void main(String[] args) {
System.out.println("请输入日期:(2018/03/31)");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char[] y = (s.substring(0, 4).toCharArray());
int n = (y[0]-48)*1000+(y[1]-48)*100+(y[2]-48)*10+(y[3]-48);
char[] m = (s.substring(5, 7).toCharArray());
int e = (m[0]-48)*10+(m[1]-48);
char[] d = (s.substring(8, 10).toCharArray());
int r = (d[0]-48)*10+(d[1]-48);
/*System.out.println(n);
System.out.println(e);
System.out.println(r);*/
int sum = 0;//统计天数
int er = 28;//默认二月是28天
//判断是否是闰年
if(n%4==0&&n%100!=0||n%400==0) {
er = 29;//如果是闰年则二月为29天
}
switch(1) {
case 1:
sum += r;
if(e==1) {
break;
}
case 2:
sum +=31;
if(e==2) {
break;
}
case 3:
sum +=er;
if(e==3) {
break;
}
case 4:
sum +=31;
if(e==4) {
break;
}
case 5:
sum +=30;
if(e==5) {
break;
}
case 6:
sum +=31;
if(e==6) {
break;
}
case 7:
sum +=30;
if(e==7) {
break;
}
case 8:
sum +=31;
if(e==8) {
break;
}
case 9:
sum +=31;
if(e==9) {
break;
}
case 10:
sum +=30;
if(e==10) {
break;
}
case 11:
sum +=31;
if(e==11) {
break;
}
case 12:
sum +=30;
if(e==12) {
break;
}
}
System.out.println(n+"-"+e+"-"+r+"是今年的第"+sum+"天");
}
}
import java.util.Scanner;
/**
* 根据用户输入的年份,月份,日期计算该日期是一年中的第几天?(switch穿越)
* @author
*
*/
public class Demo6 {
public static void main(String[] args) {
System.out.println("请输入日期:(2018/03/31)");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char[] y = (s.substring(0, 4).toCharArray());
int n = (y[0]-48)*1000+(y[1]-48)*100+(y[2]-48)*10+(y[3]-48);
char[] m = (s.substring(5, 7).toCharArray());
int e = (m[0]-48)*10+(m[1]-48);
char[] d = (s.substring(8, 10).toCharArray());
int r = (d[0]-48)*10+(d[1]-48);
/*System.out.println(n);
System.out.println(e);
System.out.println(r);*/
int sum = 0;//统计天数
int er = 28;//默认二月是28天
//判断是否是闰年
if(n%4==0&&n%100!=0||n%400==0) {
er = 29;//如果是闰年则二月为29天
}
switch(1) {
case 1:
sum += r;
if(e==1) {
break;
}
case 2:
sum +=31;
if(e==2) {
break;
}
case 3:
sum +=er;
if(e==3) {
break;
}
case 4:
sum +=31;
if(e==4) {
break;
}
case 5:
sum +=30;
if(e==5) {
break;
}
case 6:
sum +=31;
if(e==6) {
break;
}
case 7:
sum +=30;
if(e==7) {
break;
}
case 8:
sum +=31;
if(e==8) {
break;
}
case 9:
sum +=31;
if(e==9) {
break;
}
case 10:
sum +=30;
if(e==10) {
break;
}
case 11:
sum +=31;
if(e==11) {
break;
}
case 12:
sum +=30;
if(e==12) {
break;
}
}
System.out.println(n+"-"+e+"-"+r+"是今年的第"+sum+"天");
}
}