Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Calculate triangle area and perimeter in Java
1. Experiment
Objective: Create a class with two methods for calculating area &
parameter of triangle. Create another class and initialize the instance of
the former class and calculate the area & perimeter.
Code :-
import java.util.*;
class Main
{ public void area(int a, int b)
{ int d; d= (b*a)/2;
System.out.println("Area of Triangle is: "+d);
}
public void perimeter(int p, int q, int s)
{
int r; r=p+q+s;
System.out.println("perimeter of Triangle is: "+r);
}
}
class b
{
public static void main(String[] args)
{
2. int c,k,l,m,n;
Scanner sc=new Scanner(System.in);
System.out.println("enter values for area");
c=sc.nextInt();
k=sc.nextInt();
System.out.println("enter values for perimeter");
l=sc.nextInt();
m=sc.nextInt();
n=sc.nextInt();
Main h = new Main();
h.area(c,k);
h.perimeter(l,m,n);
}
}
Output :-