网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

下面的方法,当参数值为2的时候返回值是多少 1. public int getValue(int i) { 2. int result = 0; 3. switch (i) { 4. case 1: 5. result = result + i; 6. case 2: 7. result = result + i * 2; 8. case 3: 9. result = result + i * 3; 10. } 11. return result; 12. }

A.10

B.8

C.6

D.4

E.2

F.0


参考答案和解析
错误
更多 “下面的方法,当参数值为2的时候返回值是多少 1. public int getValue(int i) { 2. int result = 0; 3. switch (i) { 4. case 1: 5. result = result + i; 6. case 2: 7. result = result + i * 2; 8. case 3: 9. result = result + i * 3; 10. } 11. return result; 12. }A.10B.8C.6D.4E.2F.0” 相关考题
考题 关于JAVA初级的代码计算问题 下面的方法,当输入为2的时候返回值是多少?()publicintgetValue(inti){intresult=0;switch(i){case1:result=result+i;case2:result=result+i*2;case3:result=result+i*3;}returnresult;}

考题 下面程序的运行结果是#includeint fun(int a[]. int n){int result=l:for(int i=1;iresult=result*a[i];return result;}void main(){int a[3]={3,4,5};cout}A.12;B.15;C.20;D.60

考题 下面程序的运行结果是 include int fun(int a[ ] ,int n) { int result=1; for(in 下面程序的运行结果是#include<iostream.h>int fun(int a[ ] ,int n){int result=1;for(int i=1;i<n;i++)result=result * a[i] ;retum result;}void main( ){int a[3] ={3,4,5};coutA.12B.15C.20D.60

考题 下面程序段的输出结果是( )。 public class Test { public static void main ( String[] args) { int result=0; for ( int i=1;i<=5;i++) { if ( i%2==0 ) continue; result + =i; } System. out. println ("result is " + result ); } }A.result is 7B.result is 8C.result is 9D.result is 10

考题 下面程序的运行结果是( )。 #includeiostream.h int fun(int a[],int n) { int resuh=1; for(inl i=1;i11;1‘++) result=result * a[i]; retum result; } void main int a[3]={3,4,5}: coutfun(a,3)endl: }A.12B.15C.20D.60

考题 下面程序的运行结果是()。includeintfun(inta[],int n){int result=1;for(int i=“i 下面程序的运行结果是( )。 #include<iostream.h> intfun(inta[],int n) { int result=1; for(int i=“i<n;i++) result’resultxa[i]; return result; } void main() { inta[3]={3,4,5}; cout<<fun(a,3)<<endl; }A.12B.15C.20D.60

考题 假定a=3,下列程序的运行结果是()。ineludeint fun(int n);void main(){cout 假定a=3,下列程序的运行结果是( )。 #inelude<iostream.h> int fun(int n); void main() { cout<<"Please input a number:"; int a,result=0; cin>>a; result=fun(a); tout<<result<<end1; } intfun(int n) { int p=1,result=0; for(int i=1;i<=n;i++) { p*=i; result+=p; } return result; )A.4B.8C.9D.20

考题 下面程序的输出结果是 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<sizeresult==-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---1B.Catch一--2C.Catch---3D.以下都不对

考题 阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。【说明】本程序的功能是实现任意两个大整数的乘法运算,例如:输入整数1:8934793850094505800243958034985058输入整数2:234584950989689084095803583095820923二者之积:209596817742739508050978890737675662366433464256830959194834854876 8534【C++代码】include<iostream.h>const int MAXINPUTBIT=100;const int MAXRESULTBIT=500;class LargeNumber{int i,j;int temp;int one[MAXINPUTBIT+1];int onebit; //one的位数int two[MAXINPUTBIT+1];int twobit; //two的位数int result[MAXRESULTBIT+1];public:LargeNumber();~LargeNumber();int inputone(); //出错返叫0,否则返回1int inputtwo(); //同上void multiplication(); //乘void clearresult(); //清零void showresult(); //显示};LargeNumber∷LargeNumber(){for(i=0;i<=MAXINPUTBIT;i++){one[i]=0;two[i]=0;}nebit=0;twobit=0;inputone();inputtwo();}LargeNumber∷~LargeNumber(){}int LargeNumber∷inputone(){char Number[MAXINPUTBIT+1];cout<<"Please enter one:";cin>>Number;i=0;j=MAXINPUTBIT;while(Number[i]!='\0')i++;nebit=i;for(i--;i>=0;i--,j--){if(int(Number[i])>=48int(Number[i])<=57)(1); //由字符转换为数字elsereturn 0;}return 1;}int LargeNumber∷inputtwo(){char Number[MAXINPUTBIT+1];cout<<"Please enter two:";cin>>Number;i=0;j=MAXINPUTBIT;while(Number[i]!='\0')i++;twobit=i;for(i--;i>=0;i--,j--){if(int(Number[i])>=48int(Number[i])<=57)two[j]=int(Number[i]-48); //由字符转换为数字elsereturn 0;}return 1;}void LargeNumber∷multiplication() //乘法{clearresult();int m;for(i=MAXINPUTBIT;i>=0;i--){temp=two[i];for(j=(2),m=MAXINPUTBIT;m>=0;m--,j--){result[j]+=temp*one[m];if(result[j]>9){result[j-1]+=result[j]/10;(3);}}&n

考题 下面程序的运行结果是includeint fun(inta[],int n){ int result=1; for(int i=1:i 下面程序的运行结果是 #include<iostream.h> int fun(inta[],int n) { int result=1; for(int i=1:i<n;i++) result=result*a[i]; remm result; } void main() { int a[3]={3,4,5}; cout <<fun(a,3) <<end1; }A.12B.15C.20D.60

考题 下面程序的运行结果是include int fun ( int a[ ],int n){int result=1;for(int 下面程序的运行结果是 #include < iostream.h > int fun ( int a[ ],int n) { int result=1; for(int i=1;i<n;i++) result=result*a[i]; return result; } void main( ) { int a[3]={3,4,5}; cout << fun(a,A.12B.15C.20D.60

考题 假定a=3,下列程序的运行结果是()。includeint fun(int n);void main(){cout 假定a=3,下列程序的运行结果是( )。 #include<iostream.h> int fun(int n); void main() { cout<<"Please input a number:"; int a,result=0; cin>>a; result=fun(a); cout<<result<<end1; } int fun(int n) { int p=1,result=0; for(int i=1;i<=n;i++) { p*=i; result +=p; } return result; }A.4B.8C.9D.20

考题 ( 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;isize 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---1B ) Catch---2C ) Catch---3D )以上都不对

考题 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、 14B、 编译错误C、 120D、 24

考题 1. public class A {  2. public void doit() {  3. }  4. public String doit() {  5. return “a”;  6. }  7. public double doit(int x) {  8. return 1.0;  9. }  10.}  What is the result?() A、 An exception is thrown at runtime.B、 Compilation fails because of an error in line 7.C、 Compilation fails because of an error in line 4.D、 Compilation succeeds and no runtime errors with class A occur.

考题 public class Test {  public static void main(String Args[]) {  int i =1, j = 0;  switch(i) {  case 2: j +=6;  case 4: j +=1;  default: j +=2;  case 0: j +=4;  }  System.out.println(“j =” +j);  }  }  What is the result? () A、 0B、 2C、 4D、 6E、 9F、 13

考题 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、 0B、 1C、 2D、 Compilation fails.

考题 int i = 1,j = -1;  switch (i) {  case 0, 1:j = 1;  case 2: j = 2;  default; j = 0;  }  System.out.println(“j=”+j);  What is the result?()  A、 j = -1B、 j = 0C、 j = 1D、 j = 2E、 Compilation fails.

考题 1. public class test (  2. public static void main(string args[]) {  3. int 1= 0;  4. while (i)  {  5. if (i==4) {  6. break;  7. }  8. ++i;  9. }  10.    11. }  12. )   What is the value of i at line 10?()A、 0B、 3C、 4D、 5E、 The code will not compile.

考题 1. int I=1, j=0  2.    3. switch(i)  {  4. case 2:  5. j+=6;  6.    7. case 4:  8. j+=1;  9.    10. default:  11. j +=2;  12.    13. case 0:  14. j +=4;  15. }  16.      What is the value of j at line 16?()A、 0B、 1C、 2D、 4E、 6

考题 单选题int i = 1,j = -1;  switch (i) {  case 0, 1:j = 1;  case 2: j = 2;  default; j = 0;  }  System.out.println(“j=”+j);  What is the result?()A  j = -1B  j = 0C  j = 1D  j = 2E  Compilation fails.

考题 单选题1. public class ForBar  {  2. public static void main(String []args)   {  3.   int i = 0, j = 5;  4. tp: for (;;)  {  5. i ++;  6. for(;;)  7. if(i  --j) break tp;  8. }  9. system.out.printIn(“i = ” + i + “, j = “+ j);  10. }  11. }   What is the result?()A  The program runs and prints “i=1, j=0”B  The program runs and prints “i=1, j=4”C  The program runs and prints “i=3, j=4”D  The program runs and prints “i=3, j=0”E  An error at line 4 causes compilation to fail.F  An error at line 7 causes compilation to fail.

考题 单选题1. interface foo {  2. int k = 0;  3. } 4.    5. public class test implements Foo (  6. public static void main(String args[]) (  7. int i;  8. Test test = new test ();  9. i= test.k;  10.i= Test.k;  11.i= Foo.k;  12.)  13.)  14.        What is the result?()A  Compilation succeeds.B  An error at line 2 causes compilation to fail.C  An error at line 9 causes compilation to fail.D  An error at line 10 causes compilation to fail.E  An error at line 11 causes compilation to fail.

考题 单选题1. public class Boxer1 {  2. Integer i;  3. int x;  4. public Boxer1(int y) {  5. x=i+y;  6. System.out.println(x);  7. }  8. public static void main(String[] args) {  9. new Boxer1(new Integer(4));  10. }  11. }  What is the result?()A  The value “4” is printed at the command line.B  Compilation fails because of an error in line 5.C  Compilation fails because of an error in line 9.D  A NullPointerException occurs at runtime.E  A NumberFormatException occurs at runtime.F  An IllegalStateException occurs at runtime.

考题 单选题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  14B  编译错误C  120D  24

考题 单选题1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()A  Compilation succeeds and 1 is printed.B  Compilation succeeds and 2 is printed.C  An error at line 8 causes compilation to fail.D  An error at line 13 causes compilation to fail.E  An error at line 14 causes compilation to fail.

考题 单选题class Computation extends Thread {  private int num;  private boolean isComplete;  private int result;  public Computation(int num) { this.num = num; }  public synchronized void run() {  result = num * 2;  isComplete = true;  notify();  }  public synchronized int getResult() {  while (!isComplete) {  try {  wait();  } catch (InterruptedException e) { }  }  return result;  }  public static void main(String[] args) {  Computation[] computations = new Computation [4];  for (int i = 0; i  computations.length; i++) {  computations[i] = new Computation(i);  computations[i] .start();  }  for (Computation c : computations)  System.out.print(c.getResult() +“ “);  }  }  What is the result?()A  The code will deadlock.B  The code may run with no output.C  An exception is thrown at runtime.D  The code may run with output “0 6”.E  The code may run with output “2 0 6 4‟.F  The code may ruin with output “0 2 4 6”.

考题 单选题public class Test {  public static void main(String Args[]) {  int i =1, j = 0;  switch(i) {  case 2: j +=6;  case 4: j +=1;  default: j +=2;  case 0: j +=4;  }  System.out.println(“j =” +j);  }  }  What is the result? ()A  0B  2C  4D  6E  9F  13