Write a java program to print area of circle square rectangle using scanner class
Answers
Answer:
import java.util.Scanner;
public class Area
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter 1 for rectangle 2 for square and 3 for circle");
int c=sc.nextInt();
if(c==3)
{
System.out.println("Enter the radius:");
int r= sc.nextInt();
double area=(22*r*r)/7 ;
System.out.println("Area of Circle is: " + area);
}
else if(c==2)
{
System.out.println("Enter Side of Square:");
double side = sc.nextDouble();
double area = side*side;
System.out.println("Area of Square is: "+area);
}
else if(c==1)
{
System.out.print("Enter Length and Breadth of Rectangle : ");
int len = sc.nextInt();
int bre = sc.nextInt();
int area = len*bre;
System.out.print("Area = " +area);
}
else
{
System.out.print("Wrong choice");
}
}
}
Explanation: