Write an object oriented program in Java to find area of circle.

CODE

import java.util.Scanner;

/*

* Java Program to calculate area of circle

*/

public class Circle

{ public static void main(String args[]) {

// creating scanner to accept radius of circle

Scanner scanner = new Scanner(System.in);

System.out.println("Welcome in Java program to calculate area of circle");

System.out.println("Formula for calculating area of circle is 'PI*R^2'");

System.err.println("Please enter radius of circle:");

float radius = scanner.nextFloat();


double area = area(radius);

System.out.println("Area of Circle calculate by Java program is : " + area);

scanner.close();

}

public static double area(float radius) {

double interest = Math.PI * radius * radius;

return interest;

}

}

Output

Welcome in Java program to calculate area of circle

Formula forcalculating area of circle is 'PI*R^2'

Please enter radius of circle:

2

Area of Circle calculate by Java program is : 12.566370614359172

Comments

Popular posts from this blog

What is the cloud cube model? Explain in context to the Jericho cloud cube model along with its various dimensions.

Explain cloud computing reference model .

Discuss classification or taxonomy of virtualization at different levels.