Java Program : Calculate The Area and Circumference of Circle
Hello world ! This time we'd like to share you how to calculate the area and circumference of a circle.
The result of listing program above is like this :
import java.util.Scanner; import java.util.Scanner; import java.lang.Math.*; public class LuasKeliling { public static void main(String[] arguments) { Scanner in2; double res = 0; System.out.println("Please select,\n1. to define circumference of circle\n2. to define area of circle"); Scanner in1 = new Scanner(System.in); System.out.print("= "); switch(in1.nextInt()){ case 1: in2 = new Scanner(System.in); System.out.println(" Radius = "); res = Math.PI * in2.nextInt() * 2; break; case 2: in2 = new Scanner(System.in); System.out.println(" Radius = "); res = Math.PI * Math.pow(in2.nextInt(), 2); break; default: System.err.println ("Unrecognized option"); break; } System.out.println("\n Result is " + res); } }
The result of listing program above is like this :
Comments
Post a Comment