niusouti.com

给出下面程序段: if(x>0){System.out.println("Hello.");} else if(x>-3){ System.out.println("Nice to meet you!");} else{System.out.println("How are you?");} 若打印字符串"How are yoh?",则x的取值范围是( )。A.x>0B.x>-3C.x≤-3D.x≤0&x>-3

题目

给出下面程序段: if(x>0){System.out.println("Hello.");} else if(x>-3){ System.out.println("Nice to meet you!");} else{System.out.println("How are you?");} 若打印字符串"How are yoh?",则x的取值范围是( )。

A.x>0

B.x>-3

C.x≤-3

D.x≤0&x>-3


相似考题
更多“给出下面程序段:if(x>0){System.out.println("Hello.");}else if(x>-3){ System.out.println("Ni ”相关问题
  • 第1题:

    给出下面程序段: if(x>0){System.out.println("Hello.");} else if(x>-3){System.out.println("Nice to meet you!");} else{System.out.println("How are you?");} 若打印字符串“How are you?”,则x的取值范围是

    A.x>0

    B.x>-3

    C.x<=-3

    D.x<=0&x>-3


    正确答案:C
    解析:本题考查Java语言的if…else if语句。当需要处理多分支时,就可以使用 if...else if语句。其基本格式为:
      if(表达式1)语句1
      else if(表达式2)语句2
      else if(表达式3)语句3
      else 语句n
      需要注意,表达式是任意一个返回布尔型数据的表达式,不能是数值型(这比C、 C++的限制要严格):每个单一的语句后都必须有分号:语句1,语句2,……,语句 n可以为复合语句,这时要用大括号{}括起;else子句是任选的:若表达式的值为true,则程序执行语句1,否则执行语句2。
      当x>0时,执行System.out.println("Hello.")语句,否则(x=0时)执行else if后的语句;在此又有分支,当x>-3时System.out.println("Nice to meet you!”),只有当x=-3时才会执行System.out.println("How are you?"),输出“How are you?”字符串,所以选项C正确。

  • 第2题:

    给出下列代码片段: if(x>0){System.out.println("first");} else if(x>-3){System.out.println("second");} else{System.out.println("third");} 当x处于( )范围时打印字符串"second"。

    A.x>0

    B.x>-3

    C.-3<x<=0

    D.x<=-3


    正确答案:C

  • 第3题:

    给出下面代码段:x处于什么范围时打印字符串“second”。 ( ) public class forLoopStatement { public static void main(String[]args) { int x=______;//给x赋值 if(x>0){System.out.println("first");} else if(x>-3){System.out.println("second");} else{System.out.println("third");} } }

    A.x>0

    B.x>-3

    C.x<=-3

    D.x<=0&x>-3


    正确答案:D
    解析:本题考查的是if语句。要使程序打印字符串“second”,必须满足x>-3并且x=0。所以选项D是正确的。选项A中x>0,显然是打印的"first",所以选项A不正确。选项B中x>-3,它的结果有两种,如果x>0则打印"first",如果x=0&x>-3则打印"second",所以选项B不正确。选项C中x=-3,显然是打印"third",所以选项C不正确。

  • 第4题:

    给出下列代码片断: if(x>0) {System.out.println("first");} else if(x>-3){System.out.println("second");} else{System.out.println("third");} 请问x处于什么范围时将打印字符串“second”?( )

    A.x>0

    B.x>-3

    C.x<=3

    D.x<=0&x>-3


    正确答案:D
    解析:本题考查if-else语句的应用。从题中给出的代码段可以分析出来,当程序打印字符串“second”时,x的取值范围为(-3,0),即选择D。

  • 第5题:

    给出下面程序段: if(x>0) {System.out.printin("Hello.");} else if(x>-3) { System.out.println("Nice to meet you!");} else{System.out.println("How are you?");} 若打印字符串"How are you?",则x的取值范围是( )。

    A.x>0

    B.x>-3

    C.x≤-3

    D.x≤0&x>-3


    正确答案:C
    解析:本题考查Java语言的if...else if语句。当需要处理多分支时,就可以使用if...else if语句。其基本格式为:if(表达式1)语句1else if(表达式2)语句2else if(表达式3)语句3else语句n需要注意,表达式是任意一个返回布尔型数据的表达式,不能是数值型(这比C、C++的限制要严格);每个单一的语句后都必须有分号;语句1,语句2,……,语句n可以为复合语句,这时要用大括号{}括起;else子句是任选的;若表达式的值为true,则程序执行语句1,否则执行语句2。当x>0时,执行System.out.println("Hello.")语句,否则(x≤0时)执行else if后的语句,在此又有分支,当x>-3时System.out.println ("Nice to meet you!"),只有当x≤-3时才会执行System.out.println("How are you?"),输出 "How are you?”字符串,所以选项C正确。