类 myArray定义如下:
public class myArray
{
static int[] a = {21,42,16,31,23,47,35};
public void sortArray() //对数组从小到大进行排序
{ …… }
public int getMax() //返回最大的数组元素
{ …… }
public int getMin() //返回最小的数组元素
{ …… }
public float getAverage() //返回所有数组元素的平均值
{ …… }
public static void main(String[] args)
{ myArray myarray = new myArray();
myarray.sortArray();
System.out.println(myarray.getMax());
System.out.println(myarray.getMin());
System.out.println(myarray.getAverage());
}
在 main 方法中实现了数组元素最大值、最小值和平均值的输出。请编程实现 sortArray()、 getMax()、 getMin()、
getAverage()四个方法。
提示:排序完成以后,最大值即为最后一个数组元素,最小值为第一个数组元素。
请在 jsp 网页中利用脚本计算1*2*3*……*10 的值并输出。
第1题:
设有定义: class person {int num; char name[10]; public: void init(int n,char*m) }; personstd[30] 则以下叙述不正确的是( )。
A.std是一个含有30个元素的对象数组
B.std数组中的每个元素都是person类的对象
C.std数组中的每个元素都有自己的私有变量num和name
D.std数组中的每个元素都有各自的成员函数init
第2题:
A.private void fun( int n ){ //...}
B.void fun ( int n ){ //... }
C.protected void fun ( int n ) { //... }
D.public void fun ( int n ) { //... }
第3题:
本题中定义了长度为20的-维整型数组a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。 public class javal{ public static void main(String[]args){ int a[]= Int i: for a[i]=i for i++) =1: i=0;i<20;i++){ System.out.print(”a[”+i+”]=”+a[i]+”,“); }
第4题:
下面程序的功能是将一个整数数组写入二进制文件。在下画线处应填入的选项是 import java.io.*; public class XieShuzu { public static void main(String[] a) { int[]myArray={10,20,30,40}; try { DataoutputStream dos=new DataOutputStream(new FileoutputStream("ints.dat")); for(int i=0;i<myArray.1ength;i++)dos.______(myArray[i]); dos.close(); System.out.println("已经将整数数组写入二进制文件:ints.dat"); } catch(IOException ice) { System.out.println("IO Exception"); } } }
A.writeArray
B.writeByte
C.writeInt
D.writeDouble
第5题:
类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}
A.public float Method(float a,float b,float c){}
B.public float Method(float c,float d){}
C.public int Method(int a,int b){}
D.private float Method(int a,int b,int c){}
第6题:
本题的功能是计算二维数组各个元素的和。程序中定义了二维数组arr,arr有3行4列共l2个元素,程序中采用for循环语句的嵌套来计算数组中各个元素的和,并将结果保存在sum变量中,最后打印输出结果。 public class javal{ public static void main(String[] args){ int arr[][]={{l,2,3,4},{5,6,7,8},{9,10,11,12}}; int sum=0; int i=0,j=0; for(i=0; ) for( ) ; System.OUt.println("sum="+sum); } }
第7题:
A.t.f
B.this.n
C.Test.m
D.Test.n
第8题:
( 15 )请将下列栈类 Stack 补充完整
class Stack{
private:
int pList[100]; // int 数组 , 用于存放栈的元素
int top; // 栈顶元素 ( 数组下标 )
public:
Stack():top(0){}
void Push(const int &item); // 新元素 item 压入栈
int Pop(void); // 将栈顶元素弹出栈
};
void Stack::Push(const int &item){
if(top == 99) // 如果栈满 , 程序终止
exit(1);
top++; // 栈顶指针增 1
___________;
}
int Stack::Pop(){
if(top<0) // 如果栈空 , 程序终止
exit(1);
return pList[top--];
}
第9题:
请将下列栈类Stack的横线处补充完整。
class Stack{
private:
int pList[100]; ∥int数组,用于存放栈的元素
int top; ∥栈顶元素(数组下标)
public:
Stack():top(0){}
void Push(const int &item); ∥新元素item
第10题:
类testl定义如下: public class test1 { public float amethod(float a,float b){ } }
A.public foat amethod(float a,float b,foat c){ }
B.public float amethod(float c,float d){ }
C.public int amethod(int a,int b){ }
D.private float amethod(int a,int b,int c){ }