1) Area Of Circle Java Program
Below is the program to calculate the AOC in java, if you were new to java coding then we can also share the complete step by steps with detailed explanation on how this java program works, just below this code check it out...
import java.util.*;
class AreaOfCircle
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the radius:");
double r= s.nextDouble();
double area=(22*r*r)/7 ;
System.out.println("Area of Circle is: " + area);
}
}
-------------------------------end--------------------------
As we know that formula in math is :
But, if you were written like that, then the computer won’t understand, until and unless you assign the value of “PIE” is 22/7 or 3.14. And square as r * r.
Here is the explanation of the program step by step-
Step -1:
import java.util.*;
(This line is used to accept scanner class.)
Step -2:
public static void main(String args[])
( This is the main function, where the execution of program start from here onwards )
Step -3:
Scanner sc= new Scanner(System.in);
( The scanner is a class used to scan the input data which was given by the user through a output window.
so to get access on output window we have to create an object Syntax: new Scanner(); after creating an object that reference will store in variable ‘sc’.)
Step -4:
System.out.println("Enter the radius:");
( above code is giving instructions for the user to give the input for radius)
Step -5:
double r= s.nextDouble();
(For inputing the Radius.)
Step -6:
double area=(22*r*r)/7 ;
(For calculating the Area of circle.)
Step -7:
System.out.println("Area of Circle is: " + area);
(For printing the Area of circle.)
----------------------end---------------------
No comments:
Post a Comment