import java.util.Scanner;
public class cain {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a1=in.nextInt();
int b1=in.nextInt();
int c1=in.nextInt();
Triangle vm = new Triangle();
vm.ina(a1);
vm.inb(b1);
vm.inc(c1);
vm.showP();
vm.showP1();
}
public static class Triangle {
double a;
double b;
double c;
double p;
double p1;
double ar;
void ina(int a1){
a=a1;
}
void inb(int b1){
b=b1;
}
void inc(int c1){
c=c1;
}
void showP() {
if(a+b<=c||a+c<=b||c+b<=a) {
a=0;
b=0;
c=0;}
else {
a=a;
b=b;
c=c;
}
}
void showP1(){
p1=a+b+c;
p=p1/2;
ar=Math.sqrt(p * (p - a) * (p - b) * (p - c));
System.out.print("perimeter="+p1+"\n"+
"area="+String.format("%.1f", ar)+"\n"+
"a="+a+",b="+b+",c="+c);
}
}
}
定义一个描述三角形的类,根据输入的三边长,生成一个对象,最后输出周长、面积、边长。
最新推荐文章于 2023-11-13 15:33:59 发布