shapeArea.java
----------------------------------------
public interface shapeArea{
public double getArea();
public double getPerimeter();
}
----------------------------------------
Rectangle.java
----------------------------------------
import java.lang.*;
class Rectangle implements shapeArea{
private double width;
private double height;
public Rectangle(double w,double h){
width = w;
height = h;
}
public double getArea(){
return width * height;
}
public double getPerimeter(){
return width*2 + height*2;
}
public void toString0(){
//”width=1.0,heigth=2.0,perimeter=6.0,area=2.0"
System.out.print("width= ");
System.out.print(width);
System.out.print(",");
System.out.print("height= ");
System.out.print(height);
System.out.print(",");
System.out.print("perimeter= ");
System.out.print(getPerimeter());
System.out.print(",");
System.out.print("area= ");
System.out.print(getArea());
System.out.println("");
}
}
----------------------------------------
Test.java
----------------------------------------
class Test{
public static void main(String[] arg){
Rectangle aa = new Rectangle(100.1, 200.2);
aa.toString0();
}
}
----------------------------------------
汗 初级中的初级题的初级的解答
-------------------------------------
个人习惯 如果输出形式变了 以后好修改
System.out.println(""); 是打回车换行
偶然发现相关问题里有90%一样的问题 早知道不手打了
温馨提示:答案为网友推荐,仅供参考