Question

Part 2: Perimeter of a Triangle Write a program named Triangle.java that asks for the lengths of the three sides of a triangl

2 3 import java.util.Scanner; 4 public class Triangle { 5 60 public static void main(String[] args) { Scanner input = new Sca

this is what i have so far but it does not work. please help thank you
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Traignle {
   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       System.out.println("Enter the lengths of the three sides of a triangle");
       double side1 = input.nextDouble();
       double side2 = input.nextDouble();
       double side3 = input.nextDouble();
       // here we need to check every pair
       if ((side1 + side2) < side3 || (side1+side3)<side2 || (side2+side3)<side1) {
           System.out.println("Those sides do not specify a valid triangle");
}

else{
       //finding permieter using formula a+b+c
       System.out.println("The perimeter of the triangle is " + (side1 + side2 + side3));

}
   }
}

leillllilaleu Ilaiyile [Java Applicatiunil L. SUILreyallipsc-W1104-.J.c.cireyacci Enter the lengths of the three sides of a t

<terminated > Traignle [Java Application) C:\Soft\PegaEclipse-win64-4.5.2.2\Pe Enter the lengths of the three sides of a tria

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

leillllilaleu Ilaiyile [Java Applicatiunil L. SUILreyallipsc-W1104-.J.c.cireyacci Enter the lengths of the three sides of a triangle The perimeter of the triangle is 12.0

<terminated > Traignle [Java Application) C:\Soft\PegaEclipse-win64-4.5.2.2\Pe Enter the lengths of the three sides of a triangle Those sides do not specify a valid triangle

Add a comment
Know the answer?
Add Answer to:
this is what i have so far but it does not work. please help thank you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Why is my program returning 0 for the area of a triangle? public class GeometricObjects {...

    Why is my program returning 0 for the area of a triangle? public class GeometricObjects {    private String color = " white ";     private boolean filled;     private java.util.Date dateCreated;     public GeometricObjects() {         dateCreated = new java.util.Date();     }     public GeometricObjects(String color, boolean filled) {         dateCreated = new java.util.Date();         this.color = color;         this.filled = filled;     }     public String getColor() {         return color;     }     public void setColor(String color)...

  • Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3:...

    Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 :...

    Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 : # Enter three points for a triangle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle: ")) # Compute the length of the three sides side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5 side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore,...

    (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have THREE private member variables → side1, side2 and side3. Use the double data type to represent the triangle sides. In addition, please provide public methods that perform the following FIVE tasks: ▪ An input method that obtains the appropriate values for the three sides from the user. While entering the values of the three sides, please remember the triangle property that...

  • Purpose: The purpose of this lab is for you to design and implement several classes that...

    Purpose: The purpose of this lab is for you to design and implement several classes that use Inheritance. The problem: The program must handle a collection of different 2-dimensional shapes: triangles, rectangles and circles. All shapes have a color (use a Stringl and are either filled or not (use a boolean). All shapes must calculate and return their perimeter, and area. toStrina) for all shapes must implement the standardized formatting for inheritance. You are required to implement each of the...

  • Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three...

    Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three double values entered from keyboard input represent a triangle. If they don't, the computer should display the fact that (at least, in the case of non-positive input) one of the values does not form a valid triangle What makes a valid triangle? All sides must be positive and the sum...

  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

  • Modify the Triangle class (from previous code, will post under this) to throw an exception in...

    Modify the Triangle class (from previous code, will post under this) to throw an exception in the constructor and set routines if the triangle is not valid (i.e., does not satisfy the triangle inequality). Modify the main routine to prompt the user for the sides of the triangle and to catch the exception and re-prompt the user for valid triangle sides. In addition, for any valid triangle supply a method to compute and display the area of the triangle using...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT