Wednesday, July 14, 2021

8. Write a program to calculate the perimeter of a triangle having sides of length 2,3 and 5 units.

 public class Main {

      public static void main(String[] args) {

          int a = 2;

          int b 3;

          int c = 5;

          int perimeterOfATriangle = a + b + c;

          System.out.println("The perimeter of the triangle is : " + perimeterOfATriangle);

     }

}


NOTE:

  • Didn't need Scanner as it was not needed to take input from the user.
  • Used int as there was no decimal in the value.
  • We all know that perimeter of a triangle is calculated by adding all three sides which                                 I supposed a , b and c in above program.

No comments:

Post a Comment