Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
59 views

Calculate Circle Area Using Java Example: Home Fundamentals Common Java - Lang File Io Collections Applets & Awt Misc Swing

Java Examples

Uploaded by

VipinEv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Calculate Circle Area Using Java Example: Home Fundamentals Common Java - Lang File Io Collections Applets & Awt Misc Swing

Java Examples

Uploaded by

VipinEv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

HOME

FUNDAMENTALS
COMMON
JAVA.LANG
FILE IO
COLLECTIONS
APPLETS & AWT
MISC
SWING
Home Java Language Fundamentals Basic Java Examples Calculate Circle Area using Java
Example

Calculate Circle Area using Java Example


1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.

/*

*/

Calculate Circle Area using Java Example


This Calculate Circle Area using Java Example shows how to calculate
area of circle using it's radius.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CalculateCircleAreaExample {
public static void main(String[] args) {
int radius = 0;
System.out.println("Please enter radius of a circle");
try
{
//get the radius from console
BufferedReader br = new BufferedReader(newInputStreamReader(System.in));
radius = Integer.parseInt(br.readLine());
}
//if invalid value was entered
catch(NumberFormatException ne)
{
System.out.println("Invalid radius value" + ne);
System.exit(0);
}
catch(IOException ioe)
{
System.out.println("IO Error :" + ioe);
System.exit(0);
}
/*
* Area of a circle is
* pi * r * r

39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.

* where r is a radius of a circle.


*/
//NOTE : use Math.PI constant to get value of pi
double area = Math.PI * radius * radius;
}

System.out.println("Area of a circle is " + area);

}
/*
Output of Calculate Circle Area using Java Example would be
Please enter radius of a circle
19
Area of a circle is 1134.1149479459152
*/

145

Advertisement:
Receive Latest Java examples in your email:

Related Java Examples


Calculate Circle Perimeter using Java Example
Calculate Rectangle Area using Java Example
Calculate Rectangle Perimeter using Java Example
Read Number from Console and Check if it is a Palindrome Number
Read line of characters from console using InputStream
Generate Pyramid For a Given Number Example
Draw Oval & Circle in Applet Window Example
Calculate Average value of Array elements using Java Example

Advertisements

Advertise Here

Advertisement
Online Shopping - Flipkart
Download FREE Books
ORACLE MAGAZINE

ASP.NET EBOOK

JAVASCRIPT ANTHOLOGY

SIMPLY SQL

Recently Added Examples

Java StringBuffer setLength Example

StringBuffer To byte Array Java Example

StringBuffer To File Java Example

Java StringBuffer append new line example

Java StringBuffer to InputStream Example

StringBuffer Reset Java Example

StringBuffer toString Java Example

StringBuffer Trim Java Example

Java Convert int Array To String Example

Java Reverse String Array Example

Random Java Examples

Set Foreground Color Of an Applet Window Example

Remove all elements from Java TreeSet example

Reverse order of all elements of Java Vector Example

Simple Java HashSet example

Create FileOutputStream object from File object

Draw Smiley In Applet Example

Java Bubble Sort Example

Create Frame Window With Window Close Event Example

Get system time using System class

Read byte array using ByteArrayInputStream Example

Become a Facebook Fan


Copyright 2005 - 2011 Java Examples. Privacy Policy.

You might also like