Compute the diameter, area and circumference of circle in Java

Download
Download is available until [expire_date]
  • Version
  • Download 36
  • File Size 3.06 KB
  • File Count 1
  • Create Date April 26, 2016
  • Last Updated April 26, 2016

Compute the diameter, area and circumference of circle in Java

Compute the diameter, area and circumference of circle in Java

This java program has two versions; the console app and with the use of swing library (gui version).
The user will be asked to enter the radius of the circle then the program will compute its area, diameter and circumference.

Source code:

import javax.swing.*;
import java.text.*;
class AreaDiameterOfCircleGUI
{ 
public static void main(String[] args) {
String strradius;	 
double pi = 3.14159 , radius, area, diameter, circumference;
DecimalFormat numFormat = new DecimalFormat("0.00");

strradius = JOptionPane.showInputDialog(null,"Enter radius:");

radius=Double.parseDouble(strradius);

area= pi * radius * radius;
diameter= 2 * radius;
circumference = 2 * pi * radius;

JOptionPane.showMessageDialog(null,"Area: " + numFormat.format(area)  + "
" + "Diameter: " + numFormat.format(diameter) + "
" + "Circumference: " + numFormat.format(circumference));

	}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.