Advertisement
Yusufmm

UTS_No_1_IF

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