//第一个题感觉题目给的不是很完整,照样子写了,具体估计得修改下
class Student
{
public int number;
public Student(){}
public String toString()
{
return "number:" + number;
}
}
public class Test3
{
public static void main(String[] args)
{
int[] temp = {1005,1002,1003,1001,1004};
Student[] students = new Student[5];
for(int i = 0 ; i < 5; i++)
{
students[i] = new Student();
students[i].number = temp[i];
}
int minIndex = 0,minValue = students[0].number,maxIndex = 0,maxValue = students[0].number;
for(int i = 0 ; i < 5; i++)
{
if(students[i].number < minValue)
{
minValue = students[i].number;
minIndex = i;
}
if(students[i].number > maxValue)
{
maxValue = students[i].number;
maxIndex = i;
}
}
System.out.println("max : " + students[maxIndex]);
System.out.println("min : " + students[minIndex]);
}
}
//第二个题
public class Rectangle
{
private int xUp;
private int yUp;
private int xDown;
private int yDown;
public Rectangle(){};
public Rectangle(int xUp,int yUp,int xDown,int yDown)
{
this.xUp = xUp;
this.yUp = yUp;
this.xDown = xDown;
this.yDown = yDown;
}
public int getWidth()
{
return xDown - xUp;
}
public int getHeight()
{
return yDown - yUp;
}
public int computeArea()
{
return getWidth() * getHeight();
}
public String toString()
{
return "width:" + getWidth() + " height:" + getHeight() + " area:" + computeArea();
}
public static void main(String[] args)
{
Rectangle MyRectangle = new Rectangle(0, 0, 3, 3);
System.out.println(MyRectangle);
}
}