Math, asked by Rcjjnk, 11 months ago

A Java program to generate the area of circle

Answers

Answered by ᎷíssGℓαмσƦσυs
3

Answer:

In this tutorial we will see how to calculate area and circumference of circle in Java. There are two ways to do this:

1) With user interaction: Program will prompt user to enter the radius of the circle

2) Without user interaction: The radius value would be specified in the program itself.

Program 1:

/**

* @author: BeginnersBook.com

* @description: Program to calculate area and circumference of circle

* with user interaction. User will be prompt to enter the radius and

* the result will be calculated based on the provided radius value.

*/

import java.util.Scanner;

class CircleDemo

{

static Scanner sc = new Scanner(System.in);

public static void main(String args[])

{

System.out.print("Enter the radius: ");

/*We are storing the entered radius in double

* because a user can enter radius in decimals

*/

double radius = sc.nextDouble();

//Area = PI*radius*radius

double area = Math.PI * (radius * radius);

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

//Circumference = 2*PI*radius

double circumference= Math.PI * 2*radius;

System.out.println( "The circumference of the circle is:"+circumference) ;

}

}

Answered by anushkasharma8840
25

The program output is also shown below.

  1. public class Area.
  2. int r;
  3. double pi = 3.14, area;
  4. Scanner s = new Scanner(System.
  5. Stereo. out. print("Enter radius of circle:");
  6. r = s. nextInt();
  7. area = pi * r * r;
  8. System. out. println("Area of circle:"+area);
Similar questions