FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 4   



Following program shows you how to calculate triangle circumference.
This program gets triangle sides from user and calculates circumference and prints it using following formula
Circumference = side1 + side2 + side3

import java.util.Scanner;

public class MathGeometry2 {

    public static void main(String[] args) {

        double triangleSide1;
        double triangleSide2;
        double triangleSide3;

        Scanner in = new Scanner(System.in);

        System.out.println("Enter the side1 of triangle:");
        triangleSide1 = in.nextDouble();

        System.out.println("Enter the side2 of triangle:");
        triangleSide2 = in.nextDouble();

        System.out.println("Enter the side3 of triangle:");
        triangleSide3 = in.nextDouble();

        double circumferenceOfTriangle = triangleSide1 + triangleSide2 + triangleSide3;
        System.out.println("Circumference of triangle is: " + circumferenceOfTriangle);

    }
}

Output:

Enter the side1 of triangle:
20
Enter the side2 of triangle:
10
Enter the side3 of triangle:
30
Circumference of triangle is: 60.0



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News