Twitter Delicious Facebook Digg Stumbleupon Favorites More

Jumat, 03 Juni 2011

Menghitung Operasi Aritmatika

Dibawah ini merupakan Script untuk Menghitung 2 bilangan int penjumlahan, pengurangan, perkalian, pembagian, dan akar dengan bahasa pemrograman Java.

import java.util.Scanner;
public class OperasiAritmatika {
    public static void main(String[] args)
    {
      Scanner in=new Scanner(System.in);
      int a,b;
      double jum;
      garis();
      System.out.println("\tMENU UTAMA" );
      garis();
      System.out.println(" 1. PENJUMLAHAN" );
      System.out.println(" 2. PENGURANGAN" );
      System.out.println(" 3. PERKALIAN" );
      System.out.println(" 4. PEMBAGIAN" );
      System.out.println(" 5. AKAR" );
      garis();
    
      System.out.print("Pilih No : ");
      int point= in.nextInt();
      switch (point)
      {

        case 1:{  garis();
                  System.out.println(" 1. PENJUMLAHAN\n" );
                  System.out.print(" Masukan Nilai A : ");
                  a=in.nextInt();
                  System.out.print(" Masukan Nilai B : ");
                  b=in.nextInt();
                  jum=a+b;
                  System.out.println(" Jumlah = "+a+" + "+b+" = "+jum);
                  garis();
        }
                 break;
        case 2:{  garis();
                  System.out.println(" 2. PENGURANGAN" );
                  System.out.print(" Masukan Nilai A : ");
                  a=in.nextInt();
                  System.out.print(" Masukan Nilai B : ");
                  b=in.nextInt();
                  jum=a-b;
                  System.out.println(" Jumlah = "+a+" - "+b+" = "+jum);
                  garis();
        }
                 break;
        case 3:{  garis();
                  System.out.println(" 3. PERKALIAN" );
                  System.out.print(" Masukan Nilai A : ");
                  a=in.nextInt();
                  System.out.print(" Masukan Nilai B : ");
                  b=in.nextInt();
                  jum=a*b;
                  System.out.println(" Jumlah = "+a+" x "+b+" = "+jum);
                  garis();
        }
                 break;
        case 4:{  garis();
                  System.out.println(" 4. PEMBAGIAN" );
                  System.out.print(" Masukan Nilai A : ");
                  double c=in.nextDouble();
                  System.out.print(" Masukan Nilai B : ");
                  double d=in.nextDouble();
                  jum=c/d;
                  System.out.println(" Jumlah = "+c+" : "+d+" = "+jum);
                  garis();
        }
                 break;
        case 5:{  garis();
                  System.out.println(" 5. AKAR" );
                  System.out.print(" Masukan Nilai X : ");
                  double x=in.nextDouble();
                  jum=Math.sqrt(x);
                  System.out.println(" Hasilnya adalah = "+jum);
                  garis();
        }
                 break;
                 default : System.exit(0);
      }

    }
    static void garis()
  {
      System.out.println("===========================");
  }
 }

Outputnya akan tampil seperti gambar dibawah ini.

0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Mahasewa - Premium Blogger Themes | Blogger Templates