Telor_Goreng0

nomor 2 pertemuan 2

Apr 4th, 2021
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. package Pertemuan2;
  2. import java.util.Scanner;
  3. public class nomor2{
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner (System.in);
  6. int banyak,a;
  7. int temptall;
  8. System.out.print("Masukkan banyak data yang akan diinput: ");
  9. banyak = input.nextInt();
  10. String nama[]= new String[banyak];
  11. int tall[] = new int [banyak];
  12. for(;;){
  13. System.out.println(">_ Main menu _<");
  14. System.out.println("Silakan pilih yang diinginkan");
  15. System.out.println("1. Masukkan data murid ");
  16. System.out.println("2. Tampilkan data urut berdasarkan Tinggi");
  17. System.out.println("3. Exit");
  18. System.out.print("Pilihan anda: ");
  19. a = input.nextInt();
  20. switch(a){
  21. case 1: System.out.println("Masukkan data Murid (Tinggi dan Nama) ");
  22. for (int x = 0;x<banyak;x++){
  23. System.out.print("Tinggi Murid " +(x+1)+" : ");
  24. tall[x]=input.nextInt();
  25. System.out.print("Nama Murid "+(x+1)+" : ");
  26. nama[x]=input.next();
  27. System.out.println(" ");
  28. }
  29. break;
  30. case 2: for ( int i = 0; i<banyak;i++){
  31. for( int j = i+1; j<banyak; j++){
  32. if ( tall [i]<tall [j]){
  33. temptall = tall[i];
  34. tall [i]= tall [j];
  35. tall[j] = temptall;
  36. }
  37. }
  38. }
  39. for (int y = 0; y<banyak; y++){
  40. System.out.println((y+1)+". "+tall[y]+" " +nama[y]);
  41. System.out.println(" ");
  42. }
  43. break;
  44. case 3: System.exit(0);
  45. default:
  46. System.out.println("Terimakasih");
  47. }
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment