java 循环作业

### 二、编程题

1.已知2019年是猪年,请在控制台输出从1949年到2019年中所有是猪年的年份。

//已知2019年是猪年,请在控制台输出从1949年到2019年中所有是猪年的年份。
int count = 0;
int i;
for (i = 1949; i <= 2019; i += 4) {
System.out.print("猪年的年份" + i + "\t");
count++;
if (count % 5 == 0) {
System.out.println();
}

 

}


2.中国有闰年的说法。闰年的规则是:四年一闰,百年不闰,四百年再闰。(年份能够被4整除但不能被100整除算是闰年,年份能被400整除也是闰年)。请打印出1988年到2019年的所有闰年年份。

int i;
for(i=1988;i<=2019;i++){
  if((i%4==0 && i%100 !=0)||i%400 == 0){
    System.out.println(i);
  }
}

 


3.有一个容量为10L的空水桶。水桶的上面开始往里灌水,同时下面开始往出流水。第一分钟灌水的速度是1L/min,第二分钟灌水的速度是2L/min,第三分钟灌水的速度是3L/min,
以此类推。而流水的速度固定是3L/min。那么几分钟之后,水桶里能保持灌满水的状态?

int time = 1;//滴水时间
int count = 0;//水桶内水的数量
while(count<=10) {
c  ount=count-3;
if(count <=0) {
  count = 0;
}
  time++;
  count=count+time;

}
System.out.println(time);

 

posted @ 2020-04-12 00:06  严重焦虑症  阅读(679)  评论(0编辑  收藏  举报