以下是第九届蓝桥杯省赛JAVA B 组第一题:第几天
题目如下:
2000年的1月1日,是那一年的第1天。
那么,2000年的5月4日,是那一年的第几天?
因为是第一题较为简单,不做多余的解释,代码如下:
public class Main {
public static void main(String[] args) {
int dnum = 0;
int mounth,day,i;
for(mounth = 1;mounth<=4;mounth++){
if(mounth == 2){
day = 29;
}
else if(mounth%2 == 1){
day = 31;
}
else{
day = 30;
}
for(i = 1;i<=day;i++){
dnum++;
}
}
dnum += 4;
System.out.println(dnum);
}
}
希望以上代码对于需要的人有所帮助,其中有很大的不足请在评论区批评指正。