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.

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

Popular posts from this blog

Quantization of Image Data Implementation in C#

Computer Graphics Project "Planet Orbit" Source Code with Glut OpenGL

Computer Graphics Project "MINION" Source Code with Glut OpenGL