Compute the area and the circumference of the triangle in java

Posted By: Java Examples - 10:22 PM

Share

& Comment



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

About Java Examples

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.

0 comments :

Post a Comment

Thank you for vising Java90.blogspot.com

Copyright © 2016 Java Examples ACHCHUTHAN.ORG. Designed by Templateism .