[java]代码库
package chapter2;
import java.util.Scanner;
class Zyy {
double a;
double b;
double c;
double s,area;
double radius;
double Triangle(){
if ((a+b)<=c||(b+c)<=a||(c+a)<=b)
System.out.println("ERROR!");
else{
s=(a+b+c)/2;
area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
}
return area;
}
double Circle() {
area=3.14*radius*radius;
return area;
}
}
public class Shape
{
public static void main (String[] args)
{
double A,B,C,r,area1,area2;
System.out.print("三角形的边长:\n");
Scanner cin = new Scanner(System.in);
Zyy s=new Zyy();
A=cin.nextInt();
B=cin.nextInt();
C=cin.nextInt();
s.a=A;
s.b=B;
s.c=C;
area2=s.Triangle();
System.out.print("三角形的面积为:"+area2);
System.out.printf("圆的半径:");
r=cin.nextInt();
s.radius=r;
area1=s.Circle();
System.out.printf("圆的面积为:"+area1);
}
}