Java program to calculate triangle circumference

Views: 238   

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.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);



Enter the side1 of triangle:
Enter the side2 of triangle:
Enter the side3 of triangle:
Circumference of triangle is: 60.0
On By