Java Online Compiler
Example: How to Find Area of a Circle with Diameter in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// How to Find Area of a Circle with Diameter in Java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the radius of the circle::\n"); float r = in.nextFloat(); float d; float c; float a; // r = radius, d = diameter, c = circumference, a = area // It will calculate the diameter, circumference, and area d = 2 * r; c = 2 * (float)3.14 * r; a = (float)3.14 * (r * r); System.out.println("\nDiameter = " + d + " units"); System.out.println("Circumference = " + c + " units"); System.out.println("Area = " + a + " sq. units"); } }
7
Output
Clear
ADVERTISEMENTS