会JAVA编程的帮帮忙啊!

来源:百度知道 编辑:UC知道 时间:2024/06/05 06:12:09
1.已知数组 int a[]={12,34,5,7,9,10};
(1) 设计程序输出数组最大值
(2) 设计程序输出数组的平均值
2.已知有两个类:person类和student类,其中
person类包括属性name,age,构造函数person(…),输出函数printInfo(),
student类包括属性name,age,stuID,构造函数student(…),输出函数printInfo()
现要求编写程序设计实现student类继承person类。
3. 编写程序输出下列图形
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *

1.
import java.util.Arrays;
class arraytest
{
public static void main(String[] args)
{
int[] a={12,34,5,7,9,10};
Arrays.sort(a);//a[a.length-1]是最大值
int sum=sum(a);//sum是平均数
}
public static int sum(int[] a)
{
int sum=0;
for(int i=0;i<a.length;i++)
{
sum+=a[i];
}
return sum/(a.length);
}
}

2.public class Student extends Person{
protected long StuID;

public Student(){
System.out.println("Student Innitial..........");
}
public printInfo()
{
System.out.println("name is : " + this.name + "; age is : " + this.age + "stuID is " + this.stuID);
}

public static void main(String args[]){
Student s = new Student();
s.printInfo();
}
}

class Person
{
protected String name;
protected int age;