Computer Science, asked by keerthanasree2008, 3 months ago

write a java program to calculate and display the area of circle and triangle​

Answers

Answered by portugalindia567
0

Explanation:

public class Area.

int r;

double pi = 3.14, area;

Scanner s = new Scanner(System.

System. out. print("Enter radius of circle:");

r = s. nextInt();

area = pi * r * r;

System. out. println("Area of circle:"+area);

Answered by AestheticSoul
7

Required Program :-

import java.util.*;

public class area

{

public static void main(String args[])

{

Scanner in = new Scanner (System.in);

System.out.println("Enter '1' to calculate the area of a circle, '2' to calculate the area of triangle");

System.out.println("Enter your choice");

int ch = in.nextInt( );

switch (ch)

{

case 1 : System.out.println("Enter radius of the circle");

float r = in.nextFloat();

System.out.println("Area of circle =" + ((22.0/7.0)*r*r));

break;

case 2 : System.out.println("Enter base of triangle");

float b = in.nextFloat();

System.out.println("Enter height of triangle");

float h = in.nextFloat();

System.out.println("Area of triangle =" + ((1.0/2.0)*b*h));

break;

default : System.out.println("Wrong choice");

}

}

}

Similar questions