参考答案和解析
正确答案:D
更多“下列语句片段: int result; int a=17,b=6; result=(a%b>4) ? a%b:a/b; System.out.println(resul ”相关问题
  • 第1题:

    下面的语句片段中,变量result结果为( )。 public class Test { public static void main (String args[ ]) { int sum=0; int r=2; iht result=(sum==1?sum:r); System. out. println (result); } }

    A.1

    B.2

    C.10

    D.0


    正确答案:B
    解析:条件运算符?:为三元运算符,它的一般形式为:expression ? statement1:statement2。其中表达式expression的值应为一个布尔值,若该值为true,则执行语句statement1,否则执行语句statement2,而且语句statement1和statement2需要返回相同的数据类型,且该类型不能是 void。在本题中sum等于0,而不等于1,所以返回r的值为2。

  • 第2题:

    ( 17 )下列程序的输出结果是

    public class Test{

    public static void main(String[] args){

    int [] array={2,4,6,8,10};

    int size=6;

    int result=-1;

    try{

    for{int i=0;i<size && result==-1;i++}

    if(array[i]==20) result=i;

    }

    catch(ArithmeticException e){

    System.out.println( " Catch---1 " );

    catch(ArrayIndexOutOfBoundsException e){

    System.out.println( " Catch---2 " );

    catch(Exception e){

    System.out.println( " Catch---3 " );

    }

    }

    A ) Catch---1

    B ) Catch---2

    C ) Catch---3

    D )以上都不对


    正确答案:U

    答案暂缺

  • 第3题:

    11、下列语句片段的结果为: int result; int a = 17, b = 6; result = (a % b > 4)? a % b : a / b ; System,out.println(result);

    A.0

    B.1

    C.2

    D.5


    D

  • 第4题:

    下列语句片段的结果为int result;int a=17,b=6;result=(a%b>4)? a%b:a/b ;System.out.println(result);

    A. 0

    B. 1

    C. 2

    D. 5


    正确答案:D

  • 第5题:

    4.下面代码片断的输出结果是什么? byte b = 10; char c = 'b'; short s = 100; int i = 4, result1 = b * c; int result2 = ++i - b-- + s++; System.out.println("c=" + (byte) c); System.out.println("result1=" + result1); System.out.println("result2=" + result2);


    1.0