判断一个日期是这一年中的第几天
简洁的代码:
import javax.swing.JOptionPane;
public class jj {
public static void main (String [] args){
String year=JOptionPane.showInputDialog(null, "输入年份");
String month=JOptionPane.showInputDialog(null, "输入月份");
String day=JOptionPane.showInputDialog(null, "输入号数");
int y=Integer.parseInt(year);
int m=Integer.parseInt(month);
int d=Integer.parseInt(day);
int z=(m-1)*30+d;
if(((y%4)==0 && (y%100)!=0)||(y%400==0)){
switch(m){
case 1:
JOptionPane.showMessageDialog(null,d);
break;
case 2:
JOptionPane.showMessageDialog(null,z+1);
break;
case 3:
JOptionPane.showMessageDialog(null,z+1);
break;
case 4:
JOptionPane.showMessageDialog(null,z+2);
break;
case 5:
JOptionPane.showMessageDialog(null,z+2);
break;
case 6:
JOptionPane.showMessageDialog(null,z+3);
break;
case 7:
JOptionPane.showMessageDialog(null,z+3);
break;
case 8:
JOptionPane.showMessageDialog(null,z+4);
break;
case 9:
JOptionPane.showMessageDialog(null,z+4);
break;
case 10:
JOptionPane.showMessageDialog(null,z+4);
break;
case 11:
JOptionPane.showMessageDialog(null,z+5);
break;
case 12:
JOptionPane.showMessageDialog(null,z+5);
break;
}
}
else{
switch(m){
case 1:
JOptionPane.showMessageDialog(null,d);
break;
case 2:
JOptionPane.showMessageDialog(null,z+1);
break;
case 3:
JOptionPane.showMessageDialog(null,z+1);
break;
case 4:
JOptionPane.showMessageDialog(null,z+2);
break;
case 5:
JOptionPane.showMessageDialog(null,z+2);
break;
case 6:
JOptionPane.showMessageDialog(null,z+3);
break;
case 7:
JOptionPane.showMessageDialog(null,z+3);
break;
case 8:
JOptionPane.showMessageDialog(null,z+4);
break;
case 9:
JOptionPane.showMessageDialog(null,z+4);
break;
case 10:
JOptionPane.showMessageDialog(null,z+4);
break;
case 11:
JOptionPane.showMessageDialog(null,z+5);
break;
case 12:
JOptionPane.showMessageDialog(null,z+5);
break;
}
}
}
}