[java]代码库
package Y_S;
import java.util.Scanner;
class A {
double r;
double a, b, c;
double circle() {
// 圆面积
double S = 3.14 * this.r * this.r;
return S;
}
double triangle() {
// 三角形面积
double p = (a + b + c) / 2;
double S = Math.sqrt(p * (p - a) * (p - b) * (p - c));
return S;
}
}
public class F {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.printf("输入圆的半径:\n");
double R = input.nextInt();
A a = new A();
a.r = R;
double s1 = a.circle();
System.out.printf("圆的面积是:%f\n", s1);
System.out.printf("输入三角形的边长:\n");
double A = input.nextInt(), B = input.nextInt(), C = input.nextInt();
a.a = A;
a.b = B;
a.c = C;
double s2 = a.triangle();
System.out.printf("三角形的面积是:%f", s2);
}
}