Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA(JGRASP): (Compute the perimeter of a triangle) Write a programthat reads

ID: 3906658 • Letter: I

Question

IN JAVA(JGRASP):

(Compute the perimeter of a triangle) Write a programthat reads three edges for a triangle and computes the perimeter if the input is valid. Otherwise, display that the input is invalid. The input is valid if the sum of every pair of two edges is greater than the remaining edge.

Here is my code:

import java.util.Scanner;

public class Triangle
{

public static void main(String[] args)
{
//Variables
Scanner in = new Scanner(System.in);
int a,b,c;
int Perimeter;


//Display information
//Prompt the user to enter the input
System.out.print("Enter the length of the" + "three sides of a Traingle ");
a = in.nextint();
b = in.nextint();
c = in.nextint();
  
   //check if the sum of any two sides is less than or eqaul to the third side.
   if(a+b<=c || b+c<=a || a+c<=b)
{

   //display the error message
   System.out.println("ERROR:invalid" + "input ");
}

   //else case
   else
   {
perimeter = a+b+c;

//display the the result
System.out.println("The perimeter of the" + "Triangle is: " + perimeter);



}//End main

}//End class

I KEEP GETTING THE FOLLOWING ERROR: Triangle.java:53: error: reached end of file while parsing.   }//End class

***HOW DO I REMEDY MY CODE TO REMOVE THIS ERROR?

Explanation / Answer

Triangle.java


import java.util.Scanner;

public class Triangle
{

public static void main(String[] args)
{
//Variables
Scanner in = new Scanner(System.in);
int a,b,c;
int perimeter;


//Display information
//Prompt the user to enter the input
System.out.print("Enter the length of the" + "three sides of a Traingle ");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();

  
//check if the sum of any two sides is less than or eqaul to the third side.
if(a+b<=c || b+c<=a || a+c<=b)
{

//display the error message
System.out.println("ERROR:invalid" + "input ");
}

//else case
else
{
perimeter = a+b+c;

//display the the result
System.out.println("The perimeter of the " + "Triangle is: " + perimeter);


}
}//End main

}//End class

Output:

Enter the length of thethree sides of a Traingle
2
3
4
The perimeter of theTriangle is: 9