Compute the area and the circumference of the triangle in java



Source code



import java.util.*;
import java.lang.Math;
public class Triangle{
double s1,s2,s3;
Triangle(){
Scanner input=new Scanner(System.in);
System.out.println("Enter side 1 =");
s1=input.nextDouble();
System.out.println("Enter side 2 =");
s2=input.nextDouble();
System.out.println("Enter side3 =");
s3=input.nextDouble();
}
public double getCircum(){
return s1+s2+s3;
}
public double getArea(){
double s=(s1+s2+s3)/2;
double a=Math.sqrt(s*(s-s1)*(s-s2)*(s-s3));
return a;
}
public static void main (String args[]){
Triangle t=new Triangle();
System.out.println("***Cirumference of Triangle****"+t.getCircum());

System.out.println("***Area of Triangle****"+t.getArea());
}
}


Download


Download

Popular posts from this blog

The n-queens problem in Java

Convert infix to postfix using stack in Java