8.3知识总结

1、循环有哪些?有什么区别?

循环分为:while do…while for

Whilefor都是先判断,再执行。如果判断条件为false,则一次都不执行;而do…while是先执行,再判断,所以循环至少执行一次。

 

2、break和continue的区别是什么?

break是提前结束循环;continue是结束本次循环,进入下次循环。

 

3、以下代码哪些是死循环?

a、

int x = 0;

 

while(x<10){

   System.out.println(x);

}

死循环

 

b、

boolean x = false;

 

while(x = true){

   System.out.println(x);

}

死循环

 

c、

int x = 0;

 

do{

   System.out.println(x);

   x++;

}while(x==10);

不是死循环

 

 

d、

int x = 0;

 

do{

   System.out.println(x);

   x++;

}while(x>10);

死循环

 

 

e、

int x = 0;

 

while(x<10);{

   System.out.println(x);

  x++;

}

不是死循环

 

4、说出代码执行结果

a、

int a=1,b=10;

do{

   b-=a;

   a++;

 }while (b--<0);

 则执行循环语句后b的值为()。

8

 

b、

 inty=4;  

do{

y--;

}while(--y==0);  

System.out.println(y--);

2

 

 

 

c、

int i; 

for(i=1;i<=5;i++)  {

   if(i%2){

      System.out.println("*");

 

    }

   else{

      continue;

   }    

   System.out.println("#\n");

}

 

System.out.println("$\n");

}

编译异常, i%2 不能从 boolean 转换成 int
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值