Compute the perimeter of a triangle Write a program that rea

(Compute the perimeter of a triangle) Write a program that 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.

Solution

Sir, I dont have jdk installed in my system due to some technical problems. That\'s why I can\'t upload the screenshots as I can not run it. But I have executed this code before. This one is gonna help you out.The code is mentioned below.

In this code I have made a class perimeter, used the Scanner to take input from user, Stored the values of various inputs in s1, s2 adn s3 respectively than made an object obj which is than used to call the method triangle.

import java.util.Scanner;

import java.util.*;

public class Perimeter

{

int s1,s2,s3;

Scanner s = new Scanner(System.in);

void triangle()

    {

         System.out.print(\"Enter length of first side of triangle:\");

        s1 = s.nextInt();

        System.out.print(\"Enter length of second side of triangle:\");

        s2 = s.nextInt();

        System.out.print(\"Enter length of third side of triangle:\");

        s3 = s.nextInt();

        perimeter = s1 + s2 + s3;

        System.out.println(\"Perimeter of triangle:\"+perimeter);

    }

    public static void main(String[] args)

    {

        Perimeter obj = new Perimeter();

      obj.triangle();

    }

}

 (Compute the perimeter of a triangle) Write a program that reads three edges for a triangle and computes the perimeter if the input is valid. Otherwise, displa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site