I have written the following code so far, the point of it is to get input on the sides of a triangle, if any 2 sides are greater then the 3rd side the statement is valid, if not, invalid. Anyways, it is very basic, I am aware, but he wants very basic as it is an intro class. I cannot get the expression to work, can someone explain or provide help with it?
import java.util.Scanner;
public class TriEdges
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter one of the triangles lenghts as an interger: ");
int Length1 = input.nextInt();
System.out.println("The first interger is: " + Length1);
System.out.print("Enter another one of the triangles lenghts as an interger: ");
int Length2 = input.nextInt();
System.out.println("The first interger is: " + Length2);
System.out.print("Enter the final side of the triangle as an interger: ");
int Length3 = input.nextInt();
System.out.println("The first interger is: " + Length3);
[b] if (Lenth1 + Length2 > Length3) || (Length2 + Length3 > Length1) || (Length1 + Length3 > Length2)[/b]
System.out.println("Inputs are valid!");
else System.out.println ("The inputs are invalid, please try again.");
System.out.print("The perimeter of the triangle is : " + (Length1 + Length2 + Length3));
}
}
BOLDED is incorrect statement giving the following errors:
TriEdges.java:20: illegal start of expression
if (Lenth1 + Length2 > Length3) || (Length2 + Length3 > Length1) || (Length1 + Length3 > Length2)
^
TriEdges.java:20: not a statement
if (Lenth1 + Length2 > Length3) || (Length2 + Length3 > Length1) || (Length1 + Length3 > Length2)
^
2 errors
Question
Alladaskill17
I have written the following code so far, the point of it is to get input on the sides of a triangle, if any 2 sides are greater then the 3rd side the statement is valid, if not, invalid. Anyways, it is very basic, I am aware, but he wants very basic as it is an intro class. I cannot get the expression to work, can someone explain or provide help with it?
import java.util.Scanner; public class TriEdges { public static void main(String[]args) { Scanner input = new Scanner(System.in); System.out.print("Enter one of the triangles lenghts as an interger: "); int Length1 = input.nextInt(); System.out.println("The first interger is: " + Length1); System.out.print("Enter another one of the triangles lenghts as an interger: "); int Length2 = input.nextInt(); System.out.println("The first interger is: " + Length2); System.out.print("Enter the final side of the triangle as an interger: "); int Length3 = input.nextInt(); System.out.println("The first interger is: " + Length3); [b] if (Lenth1 + Length2 > Length3) || (Length2 + Length3 > Length1) || (Length1 + Length3 > Length2)[/b] System.out.println("Inputs are valid!"); else System.out.println ("The inputs are invalid, please try again."); System.out.print("The perimeter of the triangle is : " + (Length1 + Length2 + Length3)); } }BOLDED is incorrect statement giving the following errors:
Link to comment
Share on other sites
3 answers to this question
Recommended Posts