Sponsored Links
Ad by Google
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
OUTPUT:
Area of circle is => 452.3893421169302
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
Sponsored Links
0 comments:
Post a Comment