braek和continue

 

2.

分析如下Java代码,编译运行的输出结果是(   A )。(选择一项)

 

public static void main(String[ ] args) {

boolean a=true;

boolean b=false;

if (!(a&&b)) {

System.out.print("!(a&&b)");

}else if (!(a||b)) {

System.out.println("!(a||b)");

}else {

System.out.println("ab");

}

}

 

 

 

 

A

!(a&&b)

 

B.

!(a||b)

 

C.

ab

 

D.

!(a||b)ab

 

3.

下列选项中关于变量x的定义,(  BD  )可使以下switch语句编译通过。(选择项)

 

switch(x) {

    case 100 :

        System.out.println("One hundred");

        break;

    case 200 :              

        System.out.println("Two hundred");                 

        break;

    case 300 :

        System.out.println( "Three hundred");

        break;

    default :

        System.out.println( "default");    

}

 

 

 

 

A

double x = 100;

 

B.

char x = 100;

 

C.

String x = "100";

 

D.

int x = 100;

4.

阅读下列文件定入的Java代码,其执行结果是(   D  )。(选择一项)

 

public class Test {

public static void main(String[] args) {

char ch = 'c';

switch (ch) {

    case 'a':

    System.out.print("a"); break;

    case 'b':

    System.out.print("ab");

    case 'c':

    System.out.print("c");

    default:

    System.out.print("d");

}

}

}

 

 

 

 

A

a

 

B.

b

 

C.

c

 

D.

cd

5.

以下四个选项中和下面代码功能相同的是(    B )。(选择一项)

 

int i = 1;

int sum = 0;

while (i <= 100) {

if (i % 2 == 0)

sum = sum + i;

i++;

}

 

 

 

 

A

for (int x =1; x<=100;x++){ sum=sum+x;}

 

B.

for (int x =0; x<=100;x+=2){ sum=sum+x;}

 

C.

for (int x =1; x<=100;x+=2){ sum=sum+x;}

 

D.

上述全对

 

6.

以下do-while循环代码的执行结果是(  A  )。(选择一项)

 

int a=0;

int c=0;

do{

--c;

a=a-1;

}while(a>0);

System.out.println(a+"  "+c);

 

 

 

 

A.

-1  -1

 

B.

死循环

 

C.

-1  -2

 

D.

-1  0

 

7.

以下Java程序编译运行后的输出结果是(  B  )。(选择一项)

 

public class Test {

public static void main(String[] args) {int i = 0, sum = 0;

while (i <= 10) {

sum += i;

i++;

if (i % 2 == 0)

continue;

}

System.out.println(sum);

}

}

 

 

 

 

 

A

0

 

B.

55

 

C.

50

 

D.

36

8.

在Java中有如下代码,则编译运行该类的输出结果是(    D)。(选择一项)

 

public static void main(String[ ] args) {

for(int i=0;i<10;i++){

if (i%2!=0)

return;

System.out.print(i);

}

}

 

 

 

 

A

13578

 

B.

02468

 

C.

0123456789

 

D.

0

 

 

10.

下面程序执行的结果是(  C   )。(选择一项)

 

int  sum = 0;

for(int  i=1;i<=10;i++){

  sum+=i;

}

System.out.println(sum +"  "+ i);

 

 

 

 

A

55  11

 

B.

50  10

 

C.

编译错误

 

D.

运行错误

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值