单选题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?()AaBbCcDdECompilation fails.

题目
单选题
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.


相似考题
更多“boolean bool = true; if(bool = false) { System.out.println(“”相关问题
  • 第1题:

    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.

  • 第2题:

    使用函数bool()判别以下哪一个值结果为true。()

    A.bool('')

    B.bool(1)

    C.bool(0)

    D.bool([])


    参考答案:B

  • 第3题:

    boolean a=false;boolean b=true;boolean c=(a&&b)&&(!b);boolean result=(a&am

    boolean a=false; boolean b=true; boolean c=(a&&b)&&(!b); boolean result=(a&b)&(!b); 执行完后,正确的结果是( )。

    A.c=false;result=false

    B.c=true,result=true

    C.c=true;result=false

    D.c=false;result=true


    正确答案:A
    解析:本题考查Java中的运算。首先要清楚,“&&”是逻辑与运算符;“!”是逻辑非运算符;“&”是按位与运算符。按照逻辑运算符“a&&b”是false,“!b”是false,所以c是false。“a及b”是false,所以result是false。要注意区分“&&”和“&”,以及运算符之间的优先级关系,本题虽然没有涉及,但也要作为重点掌握。

  • 第4题:

    下面程序段: boolean a=false; boolean b=true; boolean c=(a||b)&&(b); boolean result=(a|b)&(b); 执行完后,正确的结果是

    A.c=false;result=false

    B.c=true,result=true

    C.c=true;result=false

    D.c=false;result=true


    正确答案:B
    解析:本题考查Java中的运算符。考试重点内容,历次考试都有题目涉及。首先要清楚,“&&”是逻辑与运算符;“&”是按位与运算符;“||”是逻辑或运算符;“|”是按位或运算符。“a||b”的结果为true,所以“true&&true”结果为true。而“a|b”的结果也为true,故result=(a|b)&(b)语句的结果也为true,选项B正确。

  • 第5题:

    下面程序段的输出结果为 public class Test { public static void main(String args[]) { boolean a,b,c; a=(3<5); b=(a==true); System.out.println(”a=”+a+”b=+b) ; c=(b==false); System.out.printhln(”b=”+b+”c=”+c) ; } }

    A.a=true b=false b=true c=false

    B.a=true b=false b=true c=true

    C.a=true b=true b=tree c=false

    D.a=false b=false b=tree c=false


    正确答案:C
    解析:本题考查关系运算符<和=。题目中a=(3<5);比较3和5的大小,因为3<5,返回true给a:b=(a==true);判断a是否为真,因为a确实为真,返回true给b;c =(b==false);判断b是否为假,因为b不为假,返回false给c。最后结果a=true,b=tree, b==true,c=false,选项C正确。

  • 第6题:

    下面程序段的输出结果为 public class Test { public static void main(String args[]) { boolean a,b,c; a=(3<5); b=(a==true); System.out.printin( "a="+a+"b="+b) ; c-(b==false); System.out.println(b="+b+"e="+c) ; } }

    A.a=true b=false b=true c=false

    B.a=true b=false b=true c=true

    C.a=true b=true b=true c=false

    D.a=false b=false b=true c=false


    正确答案:C
    解析:本题考查关系运算符和==。题目中a=(35);比较3和5的大小,因为35,返回true给a:b=(a==true);判断a是否为真,因为a确实为真,返回true给b;c=(b==false);判断b是否为假,因为b不为假,返回false给c。最后结果a=true,b==true,b=true,c=false,选项C正确。

  • 第7题:

    public void foo( boolean a, boolean b ){  if( a ) {  System.out.println( “A” );  } else if ( a && b ) {  System.out.println( “A&&B” );  } else { 17. if ( !b ) {  System.out.println( “notB” );  } else {  System.out.println( “ELSE” );  }  } }  What is correct?()  

    • A、 If a is true and b is true then the output is “A&&B”.
    • B、 If a is true and b is false then the output is “notB”.
    • C、 If a is false and b is true then the output is “ELSE”.
    • D、 If a is false and b is false then the output is “ELSE”.

    正确答案:C

  • 第8题:

    在C#中下列表达式不正确的是()。

    • A、double a,double b=2,int c=3,a=b+c
    • B、short a,byte b=2,byte c=3,a=b+c
    • C、string a,string b=”1” string c=”2” a=b+c
    • D、bool a,bool b=true,bool c=false a=b==c

    正确答案:A

  • 第9题:

    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

  • 第10题:

    假设变量bool_x是一个布尔型(逻辑型)的变量,则下面正确的赋值语句是()

    • A、bool_x="False"
    • B、bool_x=.FalsE.
    • C、bool_x=#False#
    • D、bool_x=False

    正确答案:D

  • 第11题:

    单选题
    在C#中下列表达式不正确的是()。
    A

    double a,double b=2,int c=3,a=b+c

    B

    short a,byte b=2,byte c=3,a=b+c

    C

    string a,string b=”1” string c=”2” a=b+c

    D

    bool a,bool b=true,bool c=false a=b==c


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

  • 第12题:

    单选题
    在public HttpSession getSession(boolean bool)的方法定义中,当bool为false时表明()
    A

    直接返回会话对象

    B

    当服务器已经创建了会话对象就返回该对象,否则返回null

    C

    直接返回null

    D

    当服务器已经创建了会话对象就返回该对象,否则新建一个会话对象并返回


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

  • 第13题:

    已知如下代码: boolean m=true; if (m==false) System.out.println("False"); else System.out.println("True"); 执行结果是( )。

    A.假

    B.Tree

    C.None

    D.An error will occur when running


    正确答案:B

  • 第14题:

    3下面程序段的输出结果为( )。 mblic class Test public static void main(String args[]) { boolean a,b,c; a=(3<5); b=(a==true); System.out.println("a="+a+"b="+b); c=(b=false); System.out.println("b="+b+"c="+c); } }

    A.a=true b=false b=true c=false

    B.a=true b=false b=true c=true

    C.a=true b=true b=true c=false

    D.a=false b=false b=true c=false


    正确答案:C

  • 第15题:

    下面程序段的输出结果为 public class Test { public static void main(String args[]) { boolean a,b,c; a=(3<5); b=(a==true); System.out.println("a="+a+"b="+B); c=(b==false); System.out.println("b="+b+"c="+C); } }

    A.a=true b=false b=true c=false

    B.a=true b=false b=true c=true

    C.a=true b=true b=true c=false

    D.a=false b=false b=true c=false


    正确答案:C
    解析:本题考查关系运算符和==。题目中a=(35);比较3和5的大小,因为 35,返回true给a;b=(a==true);判断a是否为真,因为a确实为真,返回true给b;c=(b==false);判断 b是否为假,因为b不为假,返回false给c。最后结果a=true,b=true,b=true,c=false,选项C正确。

  • 第16题:

    写出执行完下列代码段之后指定变量的值:

    bool x=true ,y=false,z=false;

    x=x&&y||z;

    y=x||y&&z;

    z=!(x!=y)||(y==z);

    则x=false,y=【 】,z=【 】。


    正确答案:false true
    false true 解析:执行语句“x&&y||z;”后,x的值变为false。执行“x||y&&z”后,y的值变为false,执行“!(x!=y)||y==z);”后,z的值变为true。

  • 第17题:

    下面均为Java关键字的一组是()

    A、boolean,byte,long,true

    B、byte, long,true,goto

    C、goto ,Boolean,byte,true

    D、bool, long,true,auto


    答案:A

  • 第18题:

    下面程序的结果为______。include void main() { int 3=1,b=2; bool c=1; if(a>b)||c

    下面程序的结果为______。

    include<iostream.h>

    void main()

    {

    int 3=1,b=2;

    bool c=1;

    if(a>b)||c)cout<<“true”<<endl;

    else

    cout<<“false”<<endl;

    }


    正确答案:true。
    true。 解析: 本题考查的是对于逻辑运算符号的理解,”||”运算符的任何一边取值为真,则整个运算结果为真。

  • 第19题:

    在public HttpSession getSession(boolean bool)的方法定义中,当bool为false时表明()

    • A、直接返回会话对象
    • B、当服务器已经创建了会话对象就返回该对象,否则返回null
    • C、直接返回null
    • D、当服务器已经创建了会话对象就返回该对象,否则新建一个会话对象并返回

    正确答案:B

  • 第20题:

    假设变量$x=5,则表达式“$x<>4”的返回值类型是()。

    • A、bool(false)
    • B、bool(true)
    • C、int(1)
    • D、int(0)

    正确答案:B

  • 第21题:

    bool类型只有2种值,为真(true)和假(false)。()


    正确答案:正确

  • 第22题:

    单选题
    public void foo( boolean a, boolean b ){  if( a ) {  System.out.println( “A” );  } else if ( a && b ) {  System.out.println( “A&&B” );  } else { 17. if ( !b ) {  System.out.println( “notB” );  } else {  System.out.println( “ELSE” );  }  } }  What is correct?()
    A

     If a is true and b is true then the output is “A&&B”.

    B

     If a is true and b is false then the output is “notB”.

    C

     If a is false and b is true then the output is “ELSE”.

    D

     If a is false and b is false then the output is “ELSE”.


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

  • 第23题:

    判断题
    bool类型只有2种值,为真(true)和假(false)。()
    A

    B


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

  • 第24题:

    单选题
    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.