类 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 voi

题目

类 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 voi”相关问题
  • 第1题:

    已知如下类定义: 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 ) { //... }


    正确答案:CD

  • 第2题:

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


    正确答案:B
    解析:该题考查的方法重载。在 Java程序中可以在同一个类中定义多个名称相同的方法,然而这些方法的参数数量和类型却不完全相同,这种现象被成为方法重载。在本题中,选项A是正确的,虽然它的参数的类型和第二行的参数类型相同,但是它的参数数量是不同的;选项B不正确,它的参数类型和参数数量都和第二行的相同;选项C正确,它的参数类型和第二行的参数类型不同;选项D也正确,它的参数类型和数量都不和第二行的相同。

  • 第3题:

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


    正确答案:C
    解析:字节输出流首先要实现DataOutput接口,字节数据流DataOutputStream是一个实现这一接口的类。字节数据是以文件输出流FileOutputStream对象的形式作为DataOutputStream的构造方法的参数。字节数据来自二进制文件,二进制文件作为FileOutputSteam对象的构造方法的参数出现。writeInt方法是将一个int值以4字节值形式写入基础输出流中,先写入高字节,本程序中写入的是整型数值,所以答案为C。

  • 第4题:

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


    正确答案:
    第1处:new boolean[10]
    第2处:i%2 1=0
    第3处:b[i]=true
    【解析】第1处定义了一个长度为10的boolean型数组;第2处判断数组元素下标是否为奇数。第3处不为奇数的情况下数组元素值设为true。

  • 第5题:

    设有以下定义: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和name

    D.std数组中的每个元素都有各自的成员函数init


    正确答案:D

  • 第6题:

    本题的功能是用冒泡法对数组元素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]+"");

    }

    }


    正确答案:
    第1处:arr.length第2处:arr[]=arr[j]第3处:arr[j]=temp【解析】第1处从下面的循环结构可看出n的值应为数组的大小;第2处和第3处是借助临时变量把小的元素交换到前面。

  • 第7题:

    下列哪些是方法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);

    正确答案:A,C,D

  • 第8题:

    研究下面的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;i<6;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、程序结束

    正确答案:C

  • 第9题:

    哪一行定义了一个静态变量?()

    • A、public static int i;
    • B、static public int i;
    • C、public int static i;
    • D、int public static i;

    正确答案:A

  • 第10题:

    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;  }

    正确答案:B,D

  • 第11题:

    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;)

    正确答案:A,C

  • 第12题:

    单选题
    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 Long

    B

     Short Long

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


    正确答案: D
    解析: 暂无解析

  • 第13题:

    已知如下类说明: 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.f

    B.this.n

    C.Test.m

    D.Test.n


    正确答案:AD

  • 第14题:

    请将下列栈类Stack的横线处补充完整。

    class Stack{

    private:

    int pList[100]; ∥int数组,用于存放栈的元素

    int top; ∥栈顶元素(数组下标)

    public:

    Stack():top(0){}

    void Push(const int &item); ∥新元素item


    正确答案:pList[top]=item
    pList[top]=item 解析: 此题考查的是堆栈数据结构。堆栈是一种先进后出的队列,每次入栈在栈顶,出栈也在栈顶。当栈顶指针所指位置是最后一个有效数据时,下次出栈直接取出栈顶指针所指数据,然后栈顶指针再减1;入栈时需要将栈顶指针先增1,然后将数据存入栈顶指针所指位置。本题中,从Pop()数中可以看出,是先取数然后top才会减1,Push()函数应先增1再取数。所以应填入pList[top]=item。

  • 第15题:

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


    正确答案:B

  • 第16题:

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


    正确答案:B
    解析:本题主要考查方法重载,方法的重载是指多个方法可以享有相同的名字,但参数的数量或类型必须不相同(采用不同的形式参数列表),选项B不符合方法重载的要求。

  • 第17题:

    本题将数组中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]+"");

    }

    }

    }


    正确答案:
    第1处:intn第2处:arr.1ength-1第3处:n——或n=n-1或n-=l【解析】第1处使用前定义变量n;第2处和第3处遍历数组各元素。

  • 第18题:

    在注释//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; i< ia.length() -1; i++)

    B. for (int i=0; i< ia.length(); i++)

    C. for (int i=1; i< 4; i++)

    D. for (int i=0; i< ia:A.length;i++)


    正确答案:D

  • 第19题:

    给定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){}

    正确答案:A,C

  • 第20题:

    现有:  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、X
    • B、y
    • C、j
    • D、i

    正确答案:A,B,D

  • 第21题:

    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、x
    • B、 y
    • C、 i
    • D、 j

    正确答案:A,B,C

  • 第22题:

    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 Long
    • B、 Short Long
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第23题:

    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 */ } }

    正确答案:B,E