Java program to find area of circle

While learning Java, we started with converting basic calculation to using Java program. like creating calculator using Java code, adding two numbers and all. And sometimes this type of questions also asked in core Java written interview questions, although this question is not as demanded as how to balanced the parentheses using Java program.

Calculating Area of Circle
Formula to calculate area of circle: area = PI * radius * radius

package com.javamakeuse.poc;
/**
 * 
 * @author javamakeuse
 *
 */
public class Circle {
 private double radius;

 public double getRadius() {
  return radius;
 }

 public void setRadius(double radius) {
  this.radius = radius;
 }

 // area = PI * radius * radius
 public double printArea() {
  return Math.PI * radius * radius;
 }

 public static void main(String[] args) {
  Circle circle = new Circle();
  circle.setRadius(12);
  System.out.println("Area of circle is => " + circle.printArea());
 }
}


OUTPUT:
Area of circle is => 452.3893421169302

Comments

Popular posts from this blog

JSP Servlet Interview Questions For Freshers Series 1

What are the core classes and interfaces of hibernate 4

Java Banking Finance Services and Insurance (BFSI) domain interview questions