System.out.println("5" +&#

题目

System.out.println("5" + 2);的输出结果应该是()

  • A、52
  • B、7
  • C、2
  • D、5
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面程序段的输出结果是( )。 public class Test{ public static void main(String args[]){ int X,y; x=(int)Math.sqrt(5)/2+(int)Math.random*5/2; y=(int)Math.sqrt(3)/2+(int)Math.random*3/2; if(x>v) System.OUt.println("x>y"); elseif(x= =y) System.out.println("x=Y"); else System.out.println("x<y"): } }

A.x>y

B.x=Y

C.x<y

D.编译错误


正确答案:A
A。【解析】本题考查Java语言中if-else分支结构和几个标准函数语句的用法。本题中赋值号右边的两个表达式分别求两个标准函数的值,再进行整除,判断出x与y的大小。Math.sqrt计算一个数的平方根,Math.random输出[0,1)之间的随机数,本题中经过两条赋值语句后,x=1,y=0。进入分支结构后,满足if条件执行相应System.out.println("x>y");操作。

第2题:

classTestApp{publicstaticvoidmain(String[]args){intx=5;switch(x){case1:case2:case3:System.out.println(一季度”);break;case4:case5:case6:System.out.println(二季度”);case7:case8:case9:System.out.println(三季度”);break;ase10:case11:ase12:System.out.println(四季度”);break;default:System.out.println(不是有效的月份”);}}}上述程序运行后的结果是哪项?()

A.一季度

B.二季度

C.三季度

D.四季度


参考答案:B

第3题:

( 21 )阅读下面程序

public class Increment {

public static void main( String args[] ){

int c;

c = 5;

System.out.println( c );

System.out.println( c++ );

System.out.println( c );

}

}

程序运行结果是

A ) 5

6

6

B ) 5

5

6

C ) 6

7

7

D ) 6

6

6


正确答案:B

第4题:

booleanbool=true;if(bool=false){System.out.println(“a”);}elseif(bool){System.out.println(“c”);}elseif(!bool){System.out.println(“c”);}else{System.out.println(“d”);}Whatistheresult?()

A.a

B.b

C.c

D.d

E.Compilationfails.


参考答案:C
Firstofall,thesecondprintlnstatementshouldprintthecharacter‘b’insteadof‘c’.Also,theanswerisnotE.butC.Indeed,thefollowinglineisperfectlylegal:if‘(bool=false)’.TheboolvariablewillsimplytakethevalueoffalseandtheIFstatementwillbeevaluatedtofalse.Therefore,thecorrectanswerisC.

第5题:

Giventhefollowingcodefragment:1)Stringstr=null;2)if((str!=null)&&(str.length()>10)){3)System.out.println("morethan10");4)}5)elseif((str!=null)&(str.length()<5)){6)System.out.println("lessthan5");7)}8)else{System.out.println("end");}Whichlinewillcauseerror?()

A.line1

B.line2

C.line5

D.line8


参考答案:C

此题需要将代码仔细看清楚,查询没有逻辑错误,if…else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logicaloperator)的“与”应该是&&,而&是位逻辑操作符(bitwiselogicaloperator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logicalboolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。

第6题:

下列选项中哪一个编译不出现错误 ( )

A.int i=0; if(i){ System.out.println("Hi"); }

B.int il=5; int i2=5; if(i1=i2){ System.out.println("So true"); }

C.int i=1; int j=2; if(i==1||j==2) System.out.println("OK");

D.int i=1; int j=2; if (i==1 &&|j==2) System.out.println("OK");


正确答案:C
解析:该题考查的是if语句。if语句的格式为:if布尔表达式)语句1;else语句2;选项A、B和D中的条件判断都不是布尔表达式,所以编译会出现错误。选项C中的判断是布尔表达式,所以编译时不出现错误。

第7题:

程序:classTestApp{publicstaticvoidmain(String[]args){intx=6;if(x>l)System.out.println("x>l");elseif(x>5)System.out.println("x>5");elseif(x<10)System.out.println("xSystem.out.println("x<29");elseSystem.out.println(以上都不是”);}}上述程序运行后的结果是哪项?()

A.x>5

B.x>l

C.x<10

D.x<29


参考答案:B

第8题:

( 15 )阅读下面程序

public class Test1{

public static void main(String[] args){

System.out.println(34 + 56 - 6);

System.out.println(26*2 - 3);

System.out.println(3 * 4/2);

System.out.println(5/2);

}

}

程序运行结果是

A ) 84

49

6

2

B ) 90

25

6

2.5

C ) 84

23

12

2

D ) 68

49

14

2.5


正确答案:A

第9题:

try{intx=0;inty=5/x;}catch(Exceptione){System.out.println(Exception”);}catch(ArithmeticExceptionae){System.out.println(ArithmeticException”);}System.out.println(finished”);Whatistheresult?()

A.finished

B.Exception

C.Compilationfails.

D.ArithmeticException


参考答案:D
ThecorrectanswertothisquestionisD.Whenanintvalueisdividedbyzero,aruntimeexceptionoccurs.Therearenocompilationerrors.

第10题:

阅读下面程序 public class Increment { public static void main( String args[] ){ int c; c=5; System.out.println(C) ; System.out.println(c++); System.out.println(C) ; } }

A.5 6 6

B.5 5 6

C.6 7 7

D.6 6 6


正确答案:B
解析:本题考查的是Java增量运算符“++”。增量运算符“++”是对操作数加1,如果对浮点数进行增量操作,则结果为加1.0。++op和op++的结果都为op=op+1。但是,如果将增量运算表达式再作为其他表达式的操作数使用时,x++和++x,它们是有区别的:x++是先使用后加1。首先使用x的值进行表达式的计算,然后才对x的值加1。++x是先加1后使用。首先对x的值加1,然后使用x的值进行表达式的计算。本题源程序代码很简单,首先生成一个整型变量c,其初始值为5。第一条输出语句输出c的初始值,即5。然后,第二条输出表达式c++的结果。根据上述介绍的增量运算符的用法,先输出c的值,然后才对c的值加1。因此,第二条输出语句输出的是5,输出后c的结果才为6。最后一条输出语句显然输出结果为6。因此,本题的正确答案为B。

更多相关问题