WAP to calculate the area of triangle and volume of cylinder in java by public static void main
Answers
1) Area of a triangle.
import java.util.*;
public class TriangleArea{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
float height,base,area;
System.out.print("Enter height of the triangle: ");
height=sc.nextFloat();
System.out.print("Enter the base of the triangle: ");
base=sc.nextFloat();
sc.close();
area=base * height * 1/2.0f;
System.out.println("The area of the triangle is: "+area+" sq units.");
}
}
2. Volume of a cylinder.
import java.util.*;
public class CylinderVolume{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
double r,h,v;
System.out.print("Enter radius: ");
r=sc.nextDouble();
System.out.print("Enter height: ");
h=sc.nextDouble();
v=Math.PI * r * r * h;
System.out.println("Volume: "+Math.round(v*100)/100.0);
sc.close();
}
}
See attachments for output.

