Computer Science, asked by vive8415, 4 months ago

WAP to calculate the area of triangle and volume of cylinder in java by public static void main

Answers

Answered by anindyaadhikari13
5

\texttt{\textsf{\large{\underline{The C{o}de}:}}}

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

   }

}

\rule{300}{2}

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.

Attachments:
Similar questions