Advertisement
Yusufmm

UTS_No_1_SWITCH

Apr 10th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. package uts_semester2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * @author Yusuf
  7.  * Soal no 1 SWITCH
  8.  */
  9. public class No_1_SWITCH {
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner sc = new Scanner(System.in);
  13.  
  14.         int pilihan;
  15.         double p, l, t, r, luas, keliling, volume;
  16.         double phi = 3.14;
  17.  
  18.         System.out.println("Program menghitung luas, keliling, dan volume bidang geometri");
  19.         System.out.println("=============================================================");
  20.         System.out.println("Pilihan 1 : menghitung luas, keliling lingkaran");
  21.         System.out.println("Pilihan 2 : menghitung luas, keliling persegi");
  22.         System.out.println("Pilihan 3 : menghitung volume balok");
  23.         System.out.println("Pilihan 4 : menghitung volume tabung");
  24.         System.out.print("Masukkan pilihan : ");
  25.         pilihan = sc.nextInt();
  26.  
  27.         switch (pilihan) {
  28.             case 1:
  29.                 System.out.print("Masukkan jari-jari : ");
  30.                 r = sc.nextDouble();
  31.                 luas = phi * r * r;
  32.                 keliling = phi * (r + r);
  33.                 System.out.println("Luas lingkaran = " + luas);
  34.                 System.out.println("Keliling lingkaran = " + keliling);
  35.                 break;
  36.             case 2:
  37.                 System.out.print("Masukkan panjang : ");
  38.                 p = sc.nextDouble();
  39.                 System.out.print("Masukkan lebar : ");
  40.                 l = sc.nextDouble();
  41.                 luas = p * l;
  42.                 keliling = 2 * (p + l);
  43.                 System.out.println("Luas persegi = " + luas);
  44.                 System.out.println("Keliling persegi = " + keliling);
  45.                 break;
  46.             case 3:
  47.                 System.out.print("Masukkan panjang : ");
  48.                 p = sc.nextDouble();
  49.                 System.out.print("Masukkan lebar : ");
  50.                 l = sc.nextDouble();
  51.                 System.out.print("Masukkan tinggi : ");
  52.                 t = sc.nextDouble();
  53.                 volume = p * l * t;
  54.                 System.out.println("Volume balok = " + volume);
  55.                 break;
  56.             case 4:
  57.                 System.out.print("Masukkan jari-jari : ");
  58.                 r = sc.nextDouble();
  59.                 System.out.print("Masukkan tinggi : ");
  60.                 t = sc.nextDouble();
  61.                 volume = phi * r * r * t;
  62.                 System.out.println("Volume tabung = " + volume);
  63.                 break;
  64.             default:
  65.                 System.out.println("Pilihan tidak sesuai");
  66.  
  67.         }
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement