类 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题:
A.private void fun( int n ){ //...}
B.void fun ( int n ){ //... }
C.protected void fun ( int n ) { //... }
D.public void fun ( int n ) { //... }
第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){}
第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
第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]+","); } }
第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
第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]+"");
}
}
第7题:
下列哪些是方法public int add (int a)的重载方法?()
第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("程序结束");} } } 输出结果将是()。
第9题:
哪一行定义了一个静态变量?()
第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?()
第11题:
public class MethodOver { public void setVar (int a, int b, float c) { } } Which two overload the setVar method?()
第12题:
int Long
Short Long
Compilation fails.
An exception is thrown at runtime.
第13题:
A.t.f
B.this.n
C.Test.m
D.Test.n
第14题:
请将下列栈类Stack的横线处补充完整。
class Stack{
private:
int pList[100]; ∥int数组,用于存放栈的元素
int top; ∥栈顶元素(数组下标)
public:
Stack():top(0){}
void Push(const int &item); ∥新元素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){ }
第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) { }
第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]+"");
;
}
}
}
第18题:
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++)
第19题:
给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test { public void cal(int x, int y, int z) { } //A }
第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处可以访问的变量是哪些?()
第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处可以访问的变量是哪些?()
第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?()
第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?()