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 的值并输出。
[主观题]类 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 stati
[单选题]类定义如下: class TestClass { public: TestClass (){cout<<1;} }; 则执行语句TestClass a,b[2] ,*p[2];后,程序的输出结果是( )。A.11B.111C.1111D.11111
[单选题]类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){ }
[单选题]命令“DIME myArray(10,10)”执行后,myArray(5,5)的值为( )。A. OB. 5C. .T.D. .F.
[单选题]有如下类定义:class A{char *a;public:A.():*(0){}A.(char * aA){//把aa所指字符串拷贝到a所指向的存储空间a=________;strcpy(a,aA);}~A(){delete[]a;}};横线处应填写的表达式是A.new char[strlen(aA)+1]B.char[strlen(aA)+1]C.char[strlen(aA)]D.new char[sizeof(aA)-1]
[单选题]有如下类定义class MyClasspublic:Private:int data;};若要为MyClass类重载流输入运算符>>,使得程序中可以“cin>>obj;”形式输入MyClass类的对象obj,则横线处的声明语句应为( )。A.) friend istream& operator>>(istream& is, MyClass&A);B.) friend istream& operator>>(istream& is, MyClassA);C.
[单选题]有如下类定义:class Sample {public;Sample(int x):ref(x){} //①private:Sample():ref(0){) //②static int val=5; //③const int ref; //④};上述程序段中,错误的语句是( )。A.) ①B.) ②C.) ③D.) ④A.B.C.D.
[试题]( 11 )有如下类定义:class Sample{public:Sample();~Sample();Private:Static int date;};将静态数据成员 data 初始化为 0 的语句是 ( 11 ) 。
[单选题]有如下类定义:class Test{public:Test(){ a = 0; c = 0;} // ①int f(int a)const{this->a = a;} // ②static int g(){return a;} // ③void h(intB. . {Test::b = b;}; // ④private:int a;static int b;const int c;};int Test::b = 0;在标注号码的行中,能被正确编译的是A. . ①B. . ②C. . ③D.
[单选题]有如下类定义: Class MyClass{ int value; public: MyClass(int n): value(n){} int getValue()const{return value;} }; 则类MyClass的构造函数的个数是A.1个B.2个C.3个D.4个