Advertisement
irfanamir

prak401

Apr 6th, 2020
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package prak401;
  2. import java.util.Scanner;
  3. public class prak401 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner masukan = new Scanner(System.in);
  7. int pilihan=9;
  8. do{
  9. System.out.println("\nMENU\n");
  10. System.out.println("1. menghitung luas persegi");
  11. System.out.println("2. Menghitung Luas Lingkaran");
  12. System.out.println("0. Keluar");
  13. System.out.println("Masukkan Pilihan Anda :");
  14. pilihan = masukan.nextInt();
  15. switch(pilihan){
  16. case 1 : luasPersegiPanjang();break;
  17. case 2 : luasLingkaran();break;
  18. }
  19. }
  20. while(pilihan !=0);
  21. }
  22.  
  23. /* irfan */
  24.  
  25. private static void luasPersegiPanjang() {
  26. Scanner masukan = new Scanner(System.in);
  27. float panjang, lebar, luas;
  28. System.out.println("Masukan nilai panjang : ");
  29. panjang = masukan.nextInt();
  30. System.out.println("Masukan nilai lebar : ");
  31. lebar = masukan.nextFloat();
  32. luas = panjang * lebar ;
  33. System.out.println("Luas persegi panjang : " + luas);
  34. }
  35.  
  36. private static void luasLingkaran() {
  37. Scanner masukan = new Scanner(System.in);
  38. float jari2, luas;
  39. System.out.println("Masukkan nilai jari jari : ");
  40. jari2 = masukan.nextFloat();
  41. luas = 3.14f * jari2 * jari2;
  42. System.out.println("Luas lingkaran :" + luas);
  43.  
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement