更多“System.out.println("5" +&#”相关问题
  • 第1题:

    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

  • 第2题:

    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)值。

  • 第3题:

    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.

  • 第4题:

    阅读下面程序 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
    解析:在第一条输出语句中,+、-是同优先级的运算符,按照左结合的原则,表达式34+56-6的值为84。在第二条输出语句中,*的优先级高于-,先计算26*2为52,再进行减法运算52-3=49。在第三条输出语句中,*与/是同优先级的运算符,按照左结合的原则,表达式3*4/2的值为6。在第四条输出语句中,两个整型数进行除法运算,结果也为整型,所以结果为2。

  • 第5题:

    阅读下面程序 publicclasslncrement{ publicstaticvoidmain(Stringargs[]){ intc; C=5; System.out.println?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增量运算符“++”。x++是先使用后加1。首先使用x的值进行表达式的计算,然后才对 x的值加1。++x是先加1后使用。首先对x的值加1,然后使用x的值进行表达式的计算。本题首先生成一个整型变量c,其初始值为5。第一条输出语句输出c的初始值,即5。然后,第二条输出表达式c抖的结果。先输出c的值,然后才对c的值加 1。因此,第二条输出语句输出的是5,输出后c的结果才为6。最后一条输出语句显然输出结果为6。因此,本题的正确答案为B。

  • 第6题:

    阅读下面程序 public class Increment{ public static void main(stringargs[]){ 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
    B。【解析】本题考查的是Java增量运算符"++"。x++是先使用后加l,即首先使用X的值进行表达式的计算,然后才对x的值加1。而++x是先加1后使用,即首先对x的值加1,然后使用x的值进行表达式的计算。本题首先生成一个整型变量C,其初始值为5。第一条输出语句输出c的初始值,即5。然后,第二条输出表达式c++的结果,即先输出C的值,然后才对c的值加1,所以,第二条输出语句输出的是5,输出后c的结果才为6。最后一条输出语句输出结果为6。因此,本题的正确答案为B。

  • 第7题:

    下列代码的执行结果是( )。 PublicclassTest { Publicstaticvoidmain(Stringargs[]) { System.out.println(5/2); System.out.println(100%3.0) } }

    A.2和1

    B.2和1.0

    C.2.5和1

    D.2.5和1.0


    正确答案:B
    解析: 由于5和2都是int型,所以语句System.out.println(5/2)的输出为2。由于操作数3.0为double型(Java语言中浮点数的默认值为double型),所以结果为double型,即1.0。

  • 第8题:

    boolean bool = true; if(bool = false) { System.out.println(“a”); } else if (bool) { System.out.println(“c”); } else if (!bool) { System.out.println(“c”); } else { System.out.println(“d”); } What is the result?()  

    • A、 a
    • B、 b
    • C、 c
    • D、 d
    • E、 Compilation fails.

    正确答案:C

  • 第9题:

    try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()  

    • A、 finished
    • B、 Exception
    • C、 Compilation fails.
    • D、 Arithmetic Exception

    正确答案:D

  • 第10题:

    class TestApp{   public static void main(String[] args){   int x = 5;   switch(x){   case 1:   case 2:   case 3:   System.out.println(“一季度”);   break;   case 4:   case 5:   case 6:   System.out.println(“二季度”);   case 7:  case 8:   case 9:   System.out.println(“三季度”);   break;   ase 10:   case 11:   ase 12:   System.out.println(“四季度”);   break;   default:   System.out.println(“不是有效的月份”);  }  }  }   上述程序运行后的结果是哪项?()  

    • A、一季度
    • B、二季度
    • C、三季度
    • D、四季度

    正确答案:B

  • 第11题:

    单选题
    boolean bool = true; if(bool = false) { System.out.println(“a”); } else if (bool) { System.out.println(“c”); } else if (!bool) { System.out.println(“c”); } else { System.out.println(“d”); } What is the result?()
    A

     a

    B

     b

    C

     c

    D

     d

    E

     Compilation fails.


    正确答案: E
    解析: First of all, the second println statement should print the character ‘b’ instead of ‘c’. Also, the answer is not E. but C. Indeed, the following line is perfectly legal: if ‘(bool = false)’. The bool variable will simply take the value of false and the IF statement will be evaluated to false. Therefore, the correct answer is C. 

  • 第12题:

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

    52

    B

    7

    C

    2

    D

    5


    正确答案: A
    解析: 暂无解析

  • 第13题:

    程序: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

  • 第14题:

    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.

  • 第15题:

    阅读下面程序 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。

  • 第16题:

    阅读下面程序 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
    解析:本题考查Java的表达式运算。
      程序中包含四条输出语句,运行时首先计算表达式的结果,然后将结果进行输出。
      第一个表达式34+56-6,运算结果为84,然后输出。因此,运行结果的第一行显示“84”。
      第二个表达式26*2-3,*号代表乘法,运算结果为49,然后输出。因此,运行结果的
      第二行显示“49”。到此,可以判断,本题的正确答案是选项A。

  • 第17题:

    下面程序的运行结果是( )。 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
    解析:本题考查自增运算符++的使用,第一个输出语句输出c的值为5,System.out.println(c++)输出表达式c++的值,由于++在变量c之后,所以表达式c++的值为5,待输出之后,变量c的值为6。最后一个输出语句输出的c的值则为6。

  • 第18题:

    下列代码的执行结果是( )。 int length="Hell0".length; System.OUt.println(length); A.5S

    下列代码的执行结果是( )。 int length="Hell0".length; System.OUt.println(length);

    A.5

    B.2

    C.10

    D.6


    正确答案:A
    A。【解析】字符串"Hello"的长度是5,java在计算字符串长度时只计算实际字符串长度。

  • 第19题:

    以下代码的输出结果为:System.out.println(" " +2 + 3、;System.out.println(2 + 3、;System.out.println(2 + 3 +"");System.out.println(2 + "" +3、;

    A.第3行出现编译错误

    B.输出23, 5, 5 和23.

    C.输出5, 5, 5 和23.

    D.输出 23, 5, 23 和23.


    正确答案:B

     

  • 第20题:

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

    • A、52
    • B、7
    • C、2
    • D、5

    正确答案:A

  • 第21题:

    Given the following code fragment:      1) String str = null;  2) if ((str != null) && (str.length() > 10)) {     3) System.out.println("more than 10");     4) }  5) else if ((str != null) & (str.length() < 5)) {     6) System.out.println("less than 5");     7) }  8) else { System.out.println("end"); }   Which line will cause error?()    

    • A、 line 1
    • B、 line 2
    • C、 line 5
    • D、 line 8

    正确答案:C

  • 第22题:

    单选题
    class TestApp{   public static void main(String[] args){   int x = 5;   switch(x){   case 1:   case 2:   case 3:   System.out.println(“一季度”);   break;   case 4:   case 5:   case 6:   System.out.println(“二季度”);   case 7:  case 8:   case 9:   System.out.println(“三季度”);   break;   ase 10:   case 11:   ase 12:   System.out.println(“四季度”);   break;   default:   System.out.println(“不是有效的月份”);  }  }  }   上述程序运行后的结果是哪项?()
    A

    一季度

    B

    二季度

    C

    三季度

    D

    四季度


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    Given the following code fragment:      1) String str = null;  2) if ((str != null) && (str.length() > 10)) {     3) System.out.println("more than 10");     4) }  5) else if ((str != null) & (str.length() < 5)) {     6) System.out.println("less than 5");     7) }  8) else { System.out.println("end"); }   Which line will cause error?()
    A

     line 1

    B

     line 2

    C

     line 5

    D

     line 8


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

  • 第24题:

    单选题
    try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()
    A

     finished

    B

     Exception

    C

     Compilation fails.

    D

     Arithmetic Exception


    正确答案: A
    解析: The correct answer to this question is D. When an int value is divided by zero, a runtime exception occurs. There are no compilation errors.