尝试使用三角方法运行Trianle程序

时间:2018-11-03 22:47:08

标签: java class methods


您好,我正在尝试运行此三角程序,但它一直给我上图所示的错误。该程序正在编译,但是在运行时无法运行。我已经在eclipse中运行了该程序,但无法在cmd中运行它。有谁知道如何解决此错误消息?谢谢

import java.util.Scanner;

class Triangle {

int side1, side2, side3;

public Triangle() {
  side1 = 0;
  side2 = 0;
  side3 = 0;
  }

  public void getData(){

  Scanner scan = new Scanner(System.in);

  System.out.println ("Enter triangle sides in increasing size:");

  System.out.print ("    side1= ");
  side1 = scan.nextInt();

  System.out.print ("    side2= ");
  side2 = scan.nextInt();

  System.out.print ("    side3= ");
  side3 = scan.nextInt();
  }

  public boolean isRight () {
       return ((side1 * side1 + side2 * side2) == (side3 * side3));
  }
  public boolean isEquilateral () {
       return ((side1==side2) && (side2==side3));
  }
  public boolean isScalene () {
   return ((side1 != side2) && (side1 != side3));
  }
  public boolean isIsosceles () {
    return ((side1 == side2) && (side2 != side3)); 

        }

   }



class TriangleEvaluator {

   public static void main (String[] args) {

      Triangle triangle1 = new Triangle();

      triangle1.getData();
      if (triangle1.isRight()) 
         System.out.println ("The triangle is right.");
        if (triangle1.isEquilateral())
             System.out.println ("The triangle is equilateral.");
             if (triangle1.isScalene())
                System.out.println ("The triangle is Scalene.");
                else if (triangle1.isIsosceles())
                    System.out.println ("The triangle is Isosceles.");


   }
}

0 个答案:

没有答案