niusouti.com

单选题class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的

题目
单选题
class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的输出是哪项?()
A

 14

B

 编译错误

C

 120

D

 24


相似考题
更多“单选题class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的”相关问题
  • 第1题:

    classTestApp{publicstaticvoidmain(String[]args){System.out.println(multiply(2,3,4,5));}publicintmultiply(int...nums){intresult=1;for(intx:nums)result*=x;returnresult;}}程序运行后的输出是哪项?()

    A.120

    B.24

    C.14

    D.编译错误


    参考答案:D

  • 第2题:

    程序:classTestApp{publicstaticvoidmain(String[]args){System.out.println(multiply(2,3,4,5));}publicintmultiply(int[]nums){intresult=1;for(intx:nums)result*=x;returnresult;}}程序运行后的输出是哪项?()

    A.14

    B.编译错误

    C.120

    D.24


    参考答案:C

  • 第3题:

    下列语句中变量result的结果为( )。 public class test { public static void main(String args[ ]) { int sum=10; int r=3; int result=sum %( ++r); System.out.println(result); } }

    A.3

    B.10

    C.2

    D.4


    正确答案:C

  • 第4题:

    有如下程序: public class MethLoad { public static void main(String args[]) { MethLoad classObj=new MethLoad(); classObj.methtest(4); classObj.methtest(0); } void methtest(double d) { double sum=2*d; System.out.println("The result is:"+sum); } void methtest(int n) { int sum=4*n; System.out.println("The result is:" +sum); } }程序的运行结果为( )。

    A.The result is:16 The result is:0

    B.The result is:0 The result is:16

    C.The result is:8 The result is:0

    D.The result is:0 The result is:8


    正确答案:A
    解析:本题考查对方法重载的掌握程度。在上面的程序中,类MethLoad中定义了两个具有相同名称methtest的方法,但这两个方法的参数不相同,编译器会根据参数的个数和参数类型来决定应该调用哪个方法。在类MethLoad中先声明了一个classObi对象,接着调用classObj的methest方法,只不过是两次调用中参数的类型不同,第1次调用的参数是int类型的4,第2次调用的参数是 double类型的0,因此要调用相对应的方法。int类型的方法返回参数值的4倍,而 double类型的方法返回参数值的2倍。

  • 第5题:

    程序:  class  TestApp{  public static void main(String[] args){  System.out.println(multiply(2,3,4,5));  }  public int multiply(int[] nums){       int result = 1;       for(int x :nums)           result *= x;       return result;   } }  程序运行后的输出是哪项?() 

    • A、 14
    • B、 编译错误
    • C、 120
    • D、 24

    正确答案:C

  • 第6题:

    interface DeclareStuff{  public static final int EASY = 3;  void doStuff(int t); }  public class TestDeclare implements DeclareStuff {  public static void main(String [] args) {  int x=5;  new TestDeclare().doStuff(++x);  }  void doStuff(int s) {  s += EASY + ++s;  System.out.println(”s “ + s);  }  }  What is the result?() 

    • A、 s 14
    • B、 s 16
    • C、 s 10
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第7题:

    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:D

  • 第8题:

    public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()   

    • A、 0
    • B、 null
    • C、 Compilation fails.
    • D、 A NullPointerException is thrown at runtime.
    • E、 An ArrayIndexOutOfBoundsException is thrown at runtime.

    正确答案:D

  • 第9题:

    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int... nums){   int result=1;   for(int x:nums)   result*=x;   return result;  }  }   程序运行后的输出是哪项?()  

    • A、120
    • B、24
    • C、14
    • D、编译错误

    正确答案:D

  • 第10题:

    单选题
    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int... nums){   int result=1;   for(int x:nums)   result*=x;   return result;  }  }   程序运行后的输出是哪项?()
    A

    120

    B

    24

    C

    14

    D

    编译错误


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

  • 第11题:

    单选题
    程序:  class  TestApp{  public static void main(String[] args){  System.out.println(multiply(2,3,4,5));  }  public int multiply(int[] nums){       int result = 1;       for(int x :nums)           result *= x;       return result;   } }  程序运行后的输出是哪项?()
    A

     14

    B

     编译错误

    C

     120

    D

     24


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

  • 第12题:

    单选题
    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的输出是哪项?()
    A

     14

    B

     编译错误

    C

     120

    D

     24


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

  • 第13题:

    classTestApp{publicstaticvoidmain(String[]args){System.out.println(multiply(2,3,4,5));}publicintmultiply(int…nums){intresult=1;for(intx:nums)result*=x;//result=result*x;returnresult;}}2、6、24、120程序运行后的输出是哪项?()

    A.14

    B.编译错误

    C.120

    D.24


    参考答案:C

  • 第14题:

    阅读下面程序

    public class OperatorsAndExpressions {

    String conditionalExpression(int score) {

    String result;

    //如果score超过60分,则结果是passed,否则是doesn't pass

    result=(score>=60)?"passed":"doesn't pass":

    System.out.println(result);

    return result;

    }

    public static void main(String args[]) {

    OperatorsAndExpressions perAndExp=new OperatorsAndExpressions();

    //条件表达式

    OperAndExp.conditionalExpression(65);

    }

    }

    程序的执行结果是______。


    正确答案:passed
    passed 解析:条件运算符的形式为expression1? expression2:expression3。如果expression1的结果为true,则计算expression2,并将结果作为整个表达式的值;如果expression1的结果为false,则计算expression3,并将结果作为整个表达式的值。本程序中,score=65,score>60的判断结果为true,所以result="passed",最后输出结果当然也是passed。

  • 第15题:

    下面的语句片段中,变量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。

  • 第16题:

    ( 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

    答案暂缺

  • 第17题:

    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的输出是哪项?()  

    • A、 14
    • B、 编译错误
    • C、 120
    • D、 24

    正确答案:C

  • 第18题:

    public class SwitchTest {  public static void main(String[] args) {  System.out.println(“value = “ + switchIt(4));  }  public static int switchIt(int x) {  int j = 1;  switch (x) {  case 1: j++; case 2: j++;  case 3: j++;  case 4: j++;  case 5: j++;  default: j++;  }  return j + x; }  }  What is the result?()  

    • A、 value = 3
    • B、 value = 4
    • C、 value = 5
    • D、 value = 6
    • E、 value = 7
    • F、 value = 8

    正确答案:F

  • 第19题:

    public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?() 

    • A、 int Long
    • B、 Short Long
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第20题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown.
    • D、 An AssertionError is thrown and finished is output.

    正确答案:A

  • 第21题:

    单选题
    public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()
    A

     0

    B

     null

    C

     Compilation fails.

    D

     A NullPointerException is thrown at runtime.

    E

     An ArrayIndexOutOfBoundsException is thrown at runtime.


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

  • 第22题:

    单选题
    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


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

  • 第23题:

    单选题
    interface DeclareStuff{  public static final int EASY = 3;  void doStuff(int t); }  public class TestDeclare implements DeclareStuff {  public static void main(String [] args) {  int x=5;  new TestDeclare().doStuff(++x);  }  void doStuff(int s) {  s += EASY + ++s;  System.out.println(”s “ + s);  }  }  What is the result?()
    A

     s 14

    B

     s 16

    C

     s 10

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


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

  • 第24题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown.

    D

     An AssertionError is thrown and finished is output.


    正确答案: D
    解析: This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the 
    correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.