A
B
C
D
E
F
第1题:
Given:
11.//insertcodehere
12.privateNmin,max;
13.publicNgetMin(){returnmin;}
14.publicNgetMax(){returnmax;}
15.publicvoidadd(Nadded){
16.if(min==null||added.doubleValue()<min.doubleValue())
17.min=added;
18.if(max==null||added.doubleValue()>max.doubleValue())
19.max=added;
20.}
21.}
Whichtwo,insertedatline11,willallowthecodetocompile?()
第2题:
下列程序的输出结果是 #include"iostream" using namespace std; int Max(int a,int b) { if(a>b) return a; else return b; } void main( ) { int m,n; m=10,n=5; int max = Max(m,n); cout<<max<<endl; }
A.10
B.程序有误
C.1
D.0
第3题:
●试题二
阅读下列程序或函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【函数2.1说明】
函数strcmp()是比较两个字符串s和t的大小。若s<t函数返回负数;若s=t函数返回0;若s>t,函数返回正数。
【函数2.1】
int strcmp(char *s,char *t)
{ while(*s && *t && (1) ){
s++;t++;
}
return (2) ;
}
【程序2.2说明】
在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个。
【程序2.2】
#includestdio.h
#define N 100
int a[N][N];
void main()
{ int row ,col,max,min,n;
/*输入合法n(<100),和输入n×n个整数到数组a的代码略*/
for (row=0;row<n;row++){
for(max=a[row][0],col=1;col<n;col++)
if( (3) )max=a[row][col];
if( (4) )min=max;
else if( (5) )min=max;
}
printf ("The min of max numbers is %d\n",min);
}
●试题二
【答案】(1)*s == *t(2) *s - *t
【解析】*s 和 *t相等才执行循环体。返回二者差值,恰好符合题目要求。
【答案】(3) a[row][col]>max (4) row == 0(5) max<min
【解析】当前值比max大,则把它赋给max。max是本行最大值。初始化min为第一行的max。该行的max比min小,则将max赋给min。
第4题:
11. public void testIfA() { 12. if(testIfB(”True”)) { 13. System.out.println(”True”); 14. } else { 15. System.out.println(”Not true”); 16. } 17. } 18. public Boolean testIfB(String str) { 19. return Boolean.valueOf(str); 20. } What is the result when method testIfA is invoked?()
第5题:
下列程序的输出结果为【 】。
inelude<iostream. h>
int &max(int &x, int &y)
{return (x>y? x: y); }
void main() {
int n=3, m=12;
max(m, n)++
cout<<"m="<<m<<", n= "<<n<<end1;
}
第6题:
在程序中,给出两个整数4和5,计算他们的和,并在屏幕上显示出来。请将程序补充完整。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
______Add
{
private int a;
private int b;
public Add(int n1,int n2)
{
a=nl;
b=n2;
}
public int getAdd()
{
return a +b;
}
}
public class basic
{
public ______void main(String[] args)
{
int n1=4, n2=5;
Add aAddB=______Add(nl,n2);
System.out.println("4+5="+aAddB.getAdd());
}
}
第7题:
fun函数的功能是首先对a所指的N行N列的矩阵找出各行中最大的数,再求这N个最大值中最小的那个数作为函数值返回,请填空。#include <stdio.h>#define N 100int fun(int(*a)[N]){ int row,col,max,min; for(row=0;row<N;row++) { for(max=a[row][0],col=1;col<N;col++) if() max=a[row][col]; if(row==0) min=max; else if() min=max; } return min;}
第8题:
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
[说明]
编写一个字符界面的Java Application 程序,接受用户输入的10个整数,并输出这10个整数的最大值和最小值。
[Java 代码]
import java. io.* ;
public class abc
{
public static void main ((1))
{int i, n=10, max=0, min=0, temp=0;
try {
BufferedReader br = new BufferedReader (
new InputStreamReader ( System.in ) );
max = min =Integer. parselnt ( br. readLine ( ) );
}. (2) ( IOExccption e ) {} ;
for ( i=2 ; i<=n ; i++ ) {
try {
BufferedReader br = new (3) (
new InputStreamReader ( System. in ) );
temp =(4) ( br. readLine ( ));
if (temp>max ) max=temp;
if (temp<min) (5)
} catch (IOException e ) {};
}
System.out.println ( "max="+max+"\nmin="+min );
}
}
第9题:
有以下程序: #include<iostream> using namespace std; Class sample { private: int n; public: sample(){} sample(int m) { n=m; } sample add(sample s1,samplc s2) { this-->n=s1.n+s2.n; return(*this); } void disp(
A.n=10
B.n=5
C.n=20
D.n=15
第10题:
10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16.); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile?()