这道java题怎么做?

2024-12-03 12:10:26
推荐回答(4个)
回答1:

package cn.gdsdxy;

import java.util.Scanner;

public class MainClass {
public static void main(String[] args) {

SquareClass obj1 = new SquareClass();
Scanner in = new Scanner(System.in);

int len = in.nextInt();
obj1.setLength(len);
System.out.println(obj1.getArea());

SquareClass obj2 = new SquareClass(10d);
System.out.println(obj2.getArea());

double length = in.nextDouble();
SquareClass obj3 = new SquareClass(length);
System.out.println(obj3.getArea());

}

static class SquareClass {
double length;

double getArea() {
double area = length * length;
return area;
}

public SquareClass(double len) {
this.length = len;
}

SquareClass() {
}

public double getLength() {
return length;
}

public void setLength(double length) {
this.length = length;
}
}
}

回答2:

回答3:

学识不够,SOrry不知道什么问题

回答4:

楼下哪位正解,答案基本正确