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

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

类 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 的值并输出。


参考答案

更多 “ 类 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 的值并输出。 ” 相关考题
考题 本题中定义了长度为20的-维整型数组a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。 public class javal{ public static void main(String[]args){ int a[]= Int i: for a[i]=i for i++) =1: i=0;i20;i++){ System.out.print(”a[”+i+”]=”+a[i]+”,“); }

考题 ( 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(top0) // 如果栈空 , 程序终止exit(1);return pList[top--];}

考题 设有定义: 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和nameD.std数组中的每个元素都有各自的成员函数init

考题 本题的功能是计算二维数组各个元素的和。程序中定义了二维数组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); } }

考题 已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?() A.private void fun( int n ){ //...}B.void fun ( int n ){ //... }C.protected void fun ( int n ) { //... }D.public void fun ( int n ) { //... }

考题 已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?() A.t.fB.this.nC.Test.mD.Test.n

考题 类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){}

考题 请将下列栈类Stack的横线处补充完整。class Stack{private:int pList[100]; ∥int数组,用于存放栈的元素int top; ∥栈顶元素(数组下标)public:Stack():top(0){}void Push(const int item); ∥新元素item

考题 下面程序的功能是将一个整数数组写入二进制文件。在下画线处应填入的选项是 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.writeArrayB.writeByteC.writeIntD.writeDouble

考题 类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){ }

考题 本题定义了一个长度为l0的boolean型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值 为false,否则为true。 public class javal{ pubhc static void main(String[]args){ boolean b[]= ; for(int i=0;i10;i++){ if( ) b[i]=false; else ; } for(int i=0;i10;i++) System.Out.print("bE"+i+"]="+b[i]+","); } }

考题 类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) { }private float Method(int a,int b,int C) { }D.private float Method(int a,int b,int C) { }

考题 设有以下定义:class person{int num;char name[10];public:void init (int n, char *m);┇};person std [30];则下面叙述中,不正确的是( )。A.std是一个含有30个元素的对象数组B.std数组中的每个元素都是person类的对象C.std数组中的每个元素都有自己的私有变量num和nameD.std数组中的每个元素都有各自的成员函数init

考题 本题将数组中arr[]={5,6,3,7,9,1}的各个元素按下标的逆序输出。public class javal{public static void main(String[]args){int arr[]={5,6,3,7,9,1};;n= ;while(n>=O){System.OUt.print(arr[n]+"");;}}}

考题 本题的功能是用冒泡法对数组元素arr[]={30,1,-9,70)进行从小到大排列。冒泡法排序是比较相邻的两个元素的大小,然后把小的元素交换到前面。public class javal{public static void main(String[]args){int i,j;int arr[]={30,1,-9,70);int n= ;for(i=0;i<n-1;i++){for(j=i+1;j<n;j++){if(arr[i]>arr[j]){int temp=arr[i];;;}}}for(i=0;i<n;i++)System.out.print(arr[i]+"");}}

考题 在注释//Start For loop 处要插入哪段代码可实现根据变量i的值定位数组ia[]的元素?public class Lin{public void amethod(){int ia[] = new int[4];//Start For loop{ia[i]=i;System.out.println(ia[i]);}}} A. for (int i=0; iB. for (int i=0; iC. for (int i=1; iD. for (int i=0; i

考题 下列哪些是方法public  int  add (int a)的重载方法?() A、  public  int  add (long a);B、  public  void  add (int a);C、  public void add (long a);D、  public  int  add (float a);

考题 给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } A、public int cal(int x,int y,float z){return 0;}B、public int cal(int x,int y,int z){return 0;}C、public void cal(int x,int z){}D、public viod cal(int z,int y,int x){}

考题 研究下面的Java代码:  public class testException{  public static void main(String args[]){       int a[]={0,1,2,3,4};      int sum=0;      try{  for(int i=1;i6;i++)  sum=sum+a[i];  System.out.println("sum="+sum);                 }      catch(ArrayIndexOutOfBoundsException ){                    System.out.println("数组越界");     }  finally{   System.out.println("程序结束");}  } }  输出结果将是()。       A、10  数组越界  程序结束B、10   程序结束C、数组越界  程序结束D、程序结束

考题 现有:  public  class  TestDemo{     private int X-2;      static int y=3;  public  void method(){      final int i=100;      int j  =10;     class Cinner {  public void mymethod(){      //Here     }     }     }     } 在Here处可以访问的变量是哪些?() A、XB、yC、jD、i

考题 哪一行定义了一个静态变量?()A、public static int i;B、static public int i;C、public int static i;D、int public static i;

考题 public class TestDemo{   private int x = 2;  static int y = 3;  public void method(){     final int i=100;     int j = 10;      class Cinner{  public void mymethod(){  //Here       }    } } }  在Here处可以访问的变量是哪些?() A、xB、 yC、 iD、 j

考题 public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }D、 public void setVar(int a, float b){  x = a;  z = b;  }E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

考题 public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?() A、 int LongB、 Short LongC、 Compilation fails.D、 An exception is thrown at runtime.

考题 public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()  A、 Private void setVar (int a, float c, int b)  { }B、 Protected void setVar (int a, int b, float c) { }C、 Public int setVar (int a, float c, int b) (return a;)D、 Public int setVar (int a, int b, float c) (return a;)E、 Protected float setVar (int a, int b, float c) (return c;)

考题 public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()A、 public class Circle implements Shape { private int radius; }B、 public abstract class Circle extends Shape { private int radius; }C、 public class Circle extends Shape { private int radius; public void draw(); }D、 public abstract class Circle implements Shape { private int radius; public void draw(); }E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

考题 单选题public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?()A  int LongB  Short LongC  Compilation fails.D  An exception is thrown at runtime.