Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Pertemuan2;
- import java.util.Scanner;
- public class nomor2{
- public static void main(String[] args) {
- Scanner input = new Scanner (System.in);
- int banyak,a;
- int temptall;
- System.out.print("Masukkan banyak data yang akan diinput: ");
- banyak = input.nextInt();
- String nama[]= new String[banyak];
- int tall[] = new int [banyak];
- for(;;){
- System.out.println(">_ Main menu _<");
- System.out.println("Silakan pilih yang diinginkan");
- System.out.println("1. Masukkan data murid ");
- System.out.println("2. Tampilkan data urut berdasarkan Tinggi");
- System.out.println("3. Exit");
- System.out.print("Pilihan anda: ");
- a = input.nextInt();
- switch(a){
- case 1: System.out.println("Masukkan data Murid (Tinggi dan Nama) ");
- for (int x = 0;x<banyak;x++){
- System.out.print("Tinggi Murid " +(x+1)+" : ");
- tall[x]=input.nextInt();
- System.out.print("Nama Murid "+(x+1)+" : ");
- nama[x]=input.next();
- System.out.println(" ");
- }
- break;
- case 2: for ( int i = 0; i<banyak;i++){
- for( int j = i+1; j<banyak; j++){
- if ( tall [i]<tall [j]){
- temptall = tall[i];
- tall [i]= tall [j];
- tall[j] = temptall;
- }
- }
- }
- for (int y = 0; y<banyak; y++){
- System.out.println((y+1)+". "+tall[y]+" " +nama[y]);
- System.out.println(" ");
- }
- break;
- case 3: System.exit(0);
- default:
- System.out.println("Terimakasih");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment