This site works best with JavaScript enabled!

Example program (Java): area of a circle

<< previous page


In this program you can calculate the area of a circle by its radius.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.io.*;
import java.util.Scanner;
import java.text.*;
class Testprogram {

public static void main(String [] args) {

	double eingabe1, ergebnis;
	DecimalFormat f = new DecimalFormat("#0");
	DecimalFormat g = new DecimalFormat("#0.00");
	System.out.println("Please enter the radius of the circle in cm!");
	Scanner eingabe = new Scanner(System.in);
	eingabe1 = Integer.valueOf(eingabe.next());
	ergebnis = (eingabe1*eingabe1)*Math.PI;
	System.out.println("The area of a circle having a radius of " + f.format(eingabe1) + " cm is: " + g.format(ergebnis) + " qcm");

}
<< previous page
Share this page
Posted on 17.10.2011 | Last modified on 20.11.2016