更新时间2018-10-08 09:07:24
import java.util.Scanner;
/* 你的代码将被嵌入到这里 */
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double w = input.nextDouble();
System.out.println("请输入宽度:");
double h = input.nextDouble();
System.out.println("请输入高度:");
Rectangle myRectangle = new Rectangle(w, h);
System.out.println(myRectangle.getArea());
System.out.println(myRectangle.getPerimeter());
input.close();
}
}
class Rectangle{
private double w=1;
private double h=1;
int area;
int perimeter;
public Rectangle(double w,double m){
this.w=w;
this.h=h;
}
public void setArea(double w,double h){
double area=0;
area=w*h;
}
public int getArea(){
return area;
}
public void setPerimeter(double w,double h){
double perimeter=0;
perimeter=2*(w+h);
}
public int getPerimeter(){
return perimeter;
}
}
输入宽度回车后才提示请输入宽度:
最后输出两个0,完全没看出你这破程序要做啥,
setPerimeter根本没有用,而且还是方法内部参数赋值,
代码复制过来根本没问题.
你程序没有问题,问题是你查下你程序的后面又有一个Main类了,在46行
你给出的程序才43行,将后面的程序删除就可以了
上一篇:在html里里弹出一个小窗体
下一篇:易语言怎么获取已运行的程序?