JAVA HELP can't figure out why this doesnt return the perimeter public class Triangle { private double side1; public Triangle(double side1, double side2, double side3) { if (side1 <= 0 || side2 <= 0 || side3 <= 0) { System.exit(0); } } public double getPerimeter (double side1, double side2, double side3 ) { double Perimeter = side1 + side2 + side3; return Perimeter; }
public static void main(String[] args) { Triangle t = new Triangle(3,4,5); t.getPerimeter(3,4,5); } }
I would first like to point out that you are not using a class to its potential. Your side variables, with the exception of your side1, are all local variables and are not accessible after the method closes.
From what you've posted, you can't determine if a perimeter is being returned. Try changing the second line of main to: System.out.println( t.getPerimeter(3,4,5) );
@rsmith6559 is correct, the perimeter IS being returned, you are just neglecting to display the results.
Join our real-time social learning platform and learn together with your friends!