import java.util.*;
public class sort
{
public static void main(String[]args)
{
String[] names = new String[3];
System.out.println("输入三个名字,每输入一个用回车确认");
Scanner sc = new Scanner(System.in);
for(int i = 0;i < 3; i ++)
{
System.out.println("第" + (i + 1) + "个名字是:");
names[i] = sc.nextLine();
}
sortNames(names);
System.out.println(Arrays.toString(names));
}
public static void sortNames(String[] array)
{
String tmp="";
for(int i=1;ifor(int j=array.length-1;j>=i;j--){
if(array[j].compareTo(array[j-1])<0){
tmp=array[j];
array[j]=array[j-1];
array[j-1]=tmp;
}
}
}
}
}
确实不需要高手,由我这个菜鸟回答你吧,呵呵。
public class cuboid{
//如果按照javaBean规范,rect应当有get和set,但是在本题中不需要
private Rectangle rect;
//height必须按照要有get和set方法,因为避免用户调用空构造器,要方面赋值
private double height;
public cuboid(){
//良好的设计习惯,方便别人的使用
}
public cuboid(Rectangle rt,double height){
this.rect=rt;
this.height=height;
}
public double getVolme(){
//因为double类型默认初始化是0,所以用户没有设置值直接获取面积的时候,返回将会是0;
return getBottomWidth()*getBottomLength()*getHeight();
}
public double getBottomWidth(){
return rect.getWidth();
}
public void setBottomWidth(double weight){
rect.setWidth(weight);
}
public double getBottomLength(){
return rect.getLength();
}
public void setBottomLength(double length){
rect.setLength(length);
}
public double getHeight(){
return this.height;
}
public void setHeight(double height){
this.height=height;
}
}
不要了侮辱高手~~~~~~~