下面的方法,当输入为2的时候返回值是多少?( )
public int getValue(int i) {
int result = 0;
switch (i) {
case 1:
result = result + i;
case 2:
result = result + i * 2;
case 3:
result = result + i * 3; }
return result; }
答案:10
当i=2 case 1 不成立 case 2 时 result = 0 + 2 * 2 result = result + i * 2;后面你没有写break; 所以result = result + i * 2;执行结束后不会停止接着执行 result = 4 + 2 * 3
第1题:
A.没有输出任何结果
B.输出结果为3
C.输出结果是3和4
D.输出结果是1、3和4
第2题:
下面程序段的输出结果是( )。 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 7
B.result is 8
C.result is 9
D.result is 10
第3题:
下列程序的输出结果是( )。#include<iostream.h>
voidmain()
(char*str="12123434";
intx1=0,x2=0,x3=0,x4=0,i;
for(i=0;str[i]!='\0';i++)
switch(str[i])
{case'1':x4++;
case'2':x3++;
case'3':x2++;
case'4':x1++;
}
cout<<x1<<","<<x2<:<","<<x3<
<","<<x4;
}
A.8,6,4,1
B.8,6,3,2
C.8,8,4,1
D.8,6.4,2
第4题:
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
第5题:
有下列程序: #include<stdi0.h> voidmain( ) { intx=1,y=0,a=0,b=0; switch(x) {case1: switch(y) { Case0:a++;break; case1:b++break; } case2:a++;b++;break; case3:a++;b++; } printf(”a=%d,b=%d\n”,a,b); }
程序的运行结果是( )。
A.a=1,b=0
B.a=2,b=2
C.a=1,b=1
D.a=2,b=1
第6题:
下列程序的输出结果是______。 main() { int i=3; switch(i) { case 1: case2:printf ("%d",i) case3: case4:break; default:printf("OK"); } }
A.0
B.3
C.OK
D.没有任何输出
第7题:
以下程序的输出结果是( )。 main { char*s="12134211"; int v[4]=(0,0,0,0),k,i; for(k=0;s[k];k++) { switch(s[k]) { case1:i=0; case2:i=1; case3:i=2; case4:i=3;} } v[i]++: } for(k=0;k<4;k++)printf("%d",v[k]);
A.4 2 1 1
B.0 0 0 8
C.4 6 7 8
D.8 8 8 8
第8题:
在窗体中使用一个文本框名为n.接受输入的值,有一个命令按钮run,事件代码如下: Private Sub run_Click( ) result = "" For i = 1 To Me!n For j = 1 To Me!n result = result + "*" Next j result = result + Chr(13) + Chr(10) Next i MsgBox result End Sub 打开窗体后,如果通过文本框输入的值为4,单击命令按钮后输出的图型是
A. * * * * * * * * * * * * * * * *
B. * * * * * * * * * * * * * * * *
C. * * * * * * * * * * * * * * * * * * * * * * * * * * * *
D. * * * * * * * * * * * * * * * *
第9题:
下面的语句片段中,变量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
第10题:
第11题:
for(inti=1;i<=3;i++){switch(i){case1:Console.write(i.ToString());case2:Console.write((i*2).ToString());case1:Console.write((i*3).ToString());}}上述关于C#代码的描述正确的是()。
第12题:
形成无限循环
输出6
输出5
输出4
第13题:
下列程序的输出结果是( )。 PublicclassTest{ Publicstaticvoidmain(String[]args){ int[]array=(2,4,6,8,10); intsize=6; intresult=-1; try{ for(inti=0;i<size&&result==-1;) if(array[i]==20)result=i; } catch(ArithmeticExceptione){ System.out.println("Catch---1"); } catch(Array IndexOutOfBoundsExceptione){ System.out.println("Catch---2"); } catch(Exceptione){ System.out.println("Catch---3"); } }
A.Catch---1
B.Catch---2
C.Catch---3
D.以上都不对
第14题:
下列程序的输出结果是______。 main() { int i=3; switch(i) { case1: case2:printf("%d",i); case3: case4:break; default: printf ("OK"); } }
A.0
B.3
C.OK
D.没有任何输出
第15题:
A.120
B.24
C.14
D.编译错误
第16题:
classComputationextendsThread{
privateintnum;
privatebooleanisComplete;
privateintresult;
publicComputation(intnum){this.num=num;}
publicsynchronizedvoidrun(){
result=num*2;
isComplete=true;
notify();
}
publicsynchronizedintgetResult(){
while(!isComplete){
try{
wait();
}catch(InterruptedExceptione){}
}
returnresult;
}
publicstaticvoidmain(String[]args){
Computation[]computations=newComputation[4];
for(inti=0;i<computations.length;i++){
computations[i]=newComputation(i);
computations[i].start();
}
for(Computationc:computations)
System.out.print(c.getResult()+);
}
}
Whatistheresult?()
第17题:
阅读以下说明和Java代码,将应填入(n)处的语句写在对应栏内。
【说明】
进行两个整数之间的比较,由考生通过输入窗口分别输入两个整数,程序比较出结果。例如:先后输入的两个数分别为25和36。
比较结果显示:
25!=36
25<36
25<=36
【Java代码】
import javax.swing.JOptionPane;
public class Java3
{
public static void main(String args[])
{
String (1) // 用户输入第1个字符串
secondNumber, // 用户输入第2个字符串
result; // 包含输出
int number1, // 比较的第1个数
number2; // 比较的第2个数
// 用户输入的第1个字符串
firstNumber =
JOptionPane. (2) ("Enter first integer:");
//读用户输入的第2个字符串
secondNumber =
JOptionPane.showlnputDialog("Enter second integer:");
将字符串类型转换成整数类型
number1= Integer. (3) (firstNumber);
number2= Integer.parselnt(secondNumber);
result= "":
if ((4))
result=number1+"=="+number2;
if (number1 != number2)
result=number1+"!="+number2;
if (number1<number2)
result=result+"\n"+number1+"<"+ number2;
if (number1>number2)
result=result+"\n"+number1+">"+number2;
if (number1<=number2)
result=result+"\n"+number1+"<="+number2;
if (numbed>=number2)
result=result+"\n"+number1+">="+number2;
//显示结果
JOptionPane.(5).(
null, result, "Comparison Results",
JOptionPane. INFORMATION_MESSAGE);
//程序正常退出
System.exit(0);
}
}
第18题:
以下程序的输出结果是 main() { int a=0,i; for(i=1;i<5;i++) { switch(i) {case0: case3:a+=2; case 1: case2:a+=3; default:a+=5; } } printf(“%d\n”,A) ; }
A.31
B.13
C.10
D.20
第19题:
下面程序的运行结果是( )。 #include<iostream.h> intfun(inta[],intn) { intresult=1; for(inti=1;i(n;i++) result=result*a[i]; returnresult; } voidmain( ) { inta[3]={3,4,5); coHt<<fun(a,3)<<endl; }
A.12
B.15
C.20
D.60
第20题:
在窗体上有一个名为num2的文本框和run11的命令按钮,事件代码如下: Private Sub run11 Click( ) Select Case num2 Case 0 Result=“0分” Case 60 T0 84 result= “通过” Case IS>=85 result= “优秀” Case Else result=“不合格” End Select MsgBox result End Sub 打开窗体,在文本框中输入80,单击命令按钮,输出结果是( )。
A.合格
B.通过
C.优秀
D.不合格
第21题:
有如下程序: 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
第22题:
若p1、p2、p3存放在存储器中相对于寄存器%ebp中地址偏移量为8、12、16的地方,返回值result存放于寄存器%edx中,则根据下面的汇编代码有() Movl 12(%ebp), %edx Movl (%edx), %eax Movl %eax, %edx Movl 8(%ebp), %ecx Addl (%ecx), %edx Movl 12(%ebp), %eax Movl %edx, (%eax) Movl %edx, %eax
第23题:
程序将报告编译错误〃提示Case标签不能贯穿到一个标签〃不能运行
运行时输出149
运行时输出123246369
运行时在屏幕上没有输出