A Program to Find the Area of a Circle
In this example, we are giving a program to find the area of a circle. The rule of finding the area of a circle is: A = πr2.
Program to find the area of a circle:
import java.util.Scanner; //Scanner class helps to get input from userclass circle {public static void main(String[] args) {Scanner s = new Scanner(System.in); //Scanner class object declarationSystem.out.println("Enter the value of radius: ");float r = s.nextFloat(); // takes float input radius from keyboard or user or run timefloat area = (3.14*r*r);System.out.println("Area of Circle: "+ area);}}
Output:
Enter the value of radius: 3 Area of Circle: 28.26