三角形的判断

来源:互联网 发布:现货软件哪个好 编辑:程序博客网 时间:2024/05/16 12:32
这次的编写也是有很多的不懂,还出现了类名上的错误,找了同学才弄明白
import java.util.Scanner;class Triangle1 {public boolean isTriangle(int a ,int b, int c ){boolean flag= false;if (a+b>c&&a+c>b&&c+b>a){flag =true;}return flag;}}class Triangle2{public String shape (int a ,int b, int c){String shape;//常量的声明if (a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b)//条件的判断{shape="直角三角形.";}else if (a*a>b*b+c*c||b*b>a*a+c*c||c*c>a*a+b*b){shape="钝角三角形.";}else if (a==b&&b==c){shape="等边三角形";}else {shape="锐角三角形";}return shape;}}class TriangleTest{public static void main(String[]args){Scanner input =new Scanner(System.in);//声明扫描仪Triangle1 t=new Triangle1();//对象的创建Triangle2 t=new Triangle2();int a,b,c;String n;do{System.out.print("请输入第一条边:");a =input.nextInt();System.out.print("请输入第二条边:");b =input.nextInt();System.out.print("请输入第三条边:");c =input.nextInt();if (t.isTriangle(a,b,c))   {System.out.println("这是一个"+t.shape(a,b,c));    }else{System.out.println("这不能构成三角形!");}System.out.print("是否继续?y/n");n=input.next();}while (n.equals("y"));System.out.print("程序结束!");}}

0 0
原创粉丝点击