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

题目

下面程序段; 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正确。
更多“下面程序段;boolean a=false;boolean b=true;boolean c=(a||b)&&(b);boolean result=(a| ”相关问题
  • 第1题:

    下列布尔变量定义中,正确并且规范的是

    A.BOOLEAN canceled=false;

    B.boolean canceled=false;

    C.boolean CANCELED=false;

    D.boolean canceled=FALSE;


    正确答案:B
    解析:本题考查Java的简单数据类型的变量定义及Java的命名约定。Java中的命名规则中包含如下几条:
      (1)变量名、方法名首单词小写,其余单词只有首字母大写;
      (2)常量完全大写;
      (3)变量命名采用完整的英文描述符,第一个字母小写,任何中间单词的首字母大写。
      Java语言区分大小写。简单数据类型布尔型用boolean表示。布尔型数据只有两个值: true(真)和false(假)。
      经过上述分析可知,选项B和选项C都能正确的定义一个布尔型变量,但是选项C的变量名CANCELED不符合Java中的命名规则,而选项B的变量名符合变量名的命名规则。因此,选项B是符合规范的布尔变量定义语句。
      本题的正确答案是选项B。

  • 第2题:

    下面程序段: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。要注意区分“&&”和“&”,以及运算符之间的优先级关系,本题虽然没有涉及,但也要作为重点掌握。

  • 第3题:

    当执行下面代码时,会输出( )。 Boolean b1 = new Boolean(true); Boolean b2 = new Boolean(true); if (b1 == b2) if (bi.equals(b2)) System. out.printin ("a"); else System. out. println ("b"); else if (bi.equals(b2)) System. out.println ("c"); else System. out.printIn("d");

    A.a

    B.b

    C.c

    D.d


    正确答案:C
    解析:本题考查对简单类型中的boolean类型的类封装的理解和掌握。对应于基本数据类型boolean的类封装是Boolean。它的构造函数的原型是Boalean(boolean value),将boolean值的数据转换为Boolean的对象。成员函数 equals()的原型是Boolean equals(Object Obj),当且仅当obj对象为Boolean对象且它的布尔值与该对象的布尔值相同时返回true。注意关系运算符==用来比较两个操作数的值是否相等。它一般只能用在基本数据类型间的比较,对于复杂的数据类型,这种比较往往都是没有意义的,对于这种没有意义的比较,其结果都为false。在本题的代码中,先创建两个Boolean类的对象b1和b2,并且它们的布尔值都为 true。然后直接对这两个对象进行==关系运算,这样的运算结果肯定为false,程序流程就走到第1层的else语句那里了,然后再用equals函数对两个对象的布尔值进行比较。因为它们的布尔值都为true,所以返回结果为true。这样输出的结果就为C。

  • 第4题:

    在Java语言中,语句“boolean? t=1;” 定义了boolean的类型变量t,并给它赋值为true


    正确答案:正确

  • 第5题:

    boolean数据类型的数据只有true和false两个值。()


    正确答案:正确

  • 第6题:

    ()导致PL/SQL中WHILE循环结束。

    • A、控制传递给EXIT语句
    • B、Boolean变量或表达式值为NULL
    • C、Boolean变量或表达式值为TRUE
    • D、Boolean变量或表达式值为FALSE

    正确答案:D

  • 第7题:

    将有三个boolean值的数组初始化为true的是()

    • A、boolean[]b=newboolean[3]
    • B、"boolean[]b={true,true,true}"
    • C、"boolean[3]b={true,true,true}"
    • D、"boolean[]b=newboolean[3];b={true,true,true}"

    正确答案:B

  • 第8题:

    int index = 1;   boolean test = new Boolean;   boolean foo= test [index];  What is the result?()

    • A、 Foo has the value of 0.
    • B、 Foo has the value of null.
    • C、 Foo has the value of true.
    • D、 Foo has the value of false.
    • E、 An exception is thrown.
    • F、 The code will not compile.

    正确答案:D

  • 第9题:

    public void testIfA(){ if(testIfB("True")){ System.out.println("True"); }else{ System.out.println("Nottrue"); } } public Boolean testIfB(Stringstr){ return Boolean.valueOf(str); } What is the result when method testIfA is invoked?()

    • A、True
    • B、Nottrue
    • C、Anexceptionisthrownatruntime.
    • D、Compilationfailsbecauseofanerroratline12.
    • E、Compilationfailsbecauseofanerroratline19.

    正确答案:A

  • 第10题:

    单选题
    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
    解析: 暂无解析

  • 第11题:

    单选题
    Which determines if “prefs” is a directory and exists on the file system?()
    A

     Boolean exists=Directory.exists (“prefs”);

    B

     Boolean exists=(new File(“prefs”)).isDir();

    C

     Boolean exists=(new Directory(“prefs”)).exists();

    D

     Boolean exists=(new File(“prefs”)).isDirectory();

    E

     Boolean exists=true;  Try{  Directory d = new Directory(“prefs”);  } catch (FileNotFoundException e) {  exists = false;  }


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

  • 第12题:

    单选题
    public void testIfA(){ if(testIfB("True")){ System.out.println("True"); }else{ System.out.println("Nottrue"); } } public Boolean testIfB(Stringstr){ return Boolean.valueOf(str); } What is the result when method testIfA is invoked?()
    A

    True

    B

    Nottrue

    C

    Anexceptionisthrownatruntime.

    D

    Compilationfailsbecauseofanerroratline12.

    E

    Compilationfailsbecauseofanerroratline19.


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

  • 第13题:

    下面程序段: 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=tree;result=false

    D.c=false;result=trae


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

  • 第14题:

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

    A、boolean,byte,long,true

    B、byte, long,true,goto

    C、goto ,Boolean,byte,true

    D、bool, long,true,auto


    答案:A

  • 第15题:

    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

  • 第16题:

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

    • A、boolean ,byte,long,assert
    • B、byte,long,true,goto
    • C、goto,boolean,byte,null
    • D、boolean,long,false,auto

    正确答案:A

  • 第17题:

    A JavaBeans component has the following field:  11. private boolean enabled;  Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()

    • A、 public void setEnabled( boolean enabled) public boolean getEnabled()
    • B、 public void setEnabled( boolean enabled) public void isEnabled()
    • C、 public void setEnabled( boolean enabled) public boolean isEnabled()
    • D、 public boolean setEnabled( boolean enabled) public boolean getEnabled()

    正确答案:A,C

  • 第18题:

    为一个boolean类型变量赋值时,可以使用()方式。

    • A、boolean=1;
    • B、booleana=(9>=10);
    • C、booleana="真";
    • D、booleana==false;

    正确答案:B

  • 第19题:

    Which determines if “prefs” is a directory and exists on the file system?()  

    • A、 Boolean exists=Directory.exists (“prefs”);
    • B、 Boolean exists=(new File(“prefs”)).isDir();
    • C、 Boolean exists=(new Directory(“prefs”)).exists();
    • D、 Boolean exists=(new File(“prefs”)).isDirectory();
    • E、 Boolean exists=true;  Try{  Directory d = new Directory(“prefs”);  } catch (FileNotFoundException e) {  exists = false;  }

    正确答案:D

  • 第20题:

    class Test4 {   public static void main(String [] args) {   boolean x = true;   boolean y = false;   short z = 42;   if((z++ = = 42) && (y = true)) z++;   if((x = false) || (++z = = 45)) z++;   System.out.println("z = " + z);   }   }   结果为:()  

    • A、z = 42
    • B、z = 44
    • C、z = 45
    • D、z = 46

    正确答案:D

  • 第21题:

    单选题
    int index = 1;  boolean[] test = new Boolean[3];  boolean foo= test [index];   What is the result?()
    A

     Foo has the value of 0.

    B

     Foo has the value of null.

    C

     Foo has the value of true.

    D

     Foo has the value of false.

    E

     An exception is thrown.

    F

     The code will not compile.


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

  • 第22题:

    单选题
    int index = 1;   boolean test = new Boolean;   boolean foo= test [index];  What is the result?()
    A

     Foo has the value of 0.

    B

     Foo has the value of null.

    C

     Foo has the value of true.

    D

     Foo has the value of false.

    E

     An exception is thrown.

    F

     The code will not compile.


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

  • 第23题:

    多选题
    A JavaBeans component has the following field:  11. private boolean enabled;  Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()
    A

    public void setEnabled( boolean enabled) public boolean getEnabled()

    B

    public void setEnabled( boolean enabled) public void isEnabled()

    C

    public void setEnabled( boolean enabled) public boolean isEnabled()

    D

    public boolean setEnabled( boolean enabled) public boolean getEnabled()


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

  • 第24题:

    判断题
    boolean数据类型的数据只有true和false两个值。()
    A

    B


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