温馨提示:因为是这几天边复习边写的所以更新有点慢,不过需要答案的小可爱们放心,会很快补上哒^ - ^
第二章
1
package com.xiujie.part_2;
import java.util.Scanner;
/**
*
* @author lxj
*
*/
public class BoxOfValue {
public static void main(String[] args) {
System.out.println("请输入长方体的长、宽、高:");
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int width = scanner.nextInt();
int height = scanner.nextInt();
Box box = new Box();
box.setInfo(length, width, height);
box.toString();
scanner.close();
}
}
class Box {
private int length;
private int width;
private int height;
public void setInfo(int x, int y, int z) {
length = x;
width = y;
height = z;
}
public int volumn() {
return length * width * height;
}
public int area() {
return 2*(length * width + length * height + width * height);
}
public String toString() {
System.out.println("长方体的长、宽、高分别是:" + length + "," + width + "," + height + ",表面积是:"
+ area() + "体积是:" + volumn());
return "计算完毕";
}
}
2、
package com.xiujie.part_2;
public class CircleTest {
public static void main(String[] args) {
Circle circle1 = new Circle();
Circle circle2 = new Circle();
circle1.setR(3);
circle2.setR(4);
circle1.showInfo();
circle2.showInfo();
}
}
class Circle