Salam Sarjana || Saya akan membahas materi Pemrograman Java tentang Percabangan, baiklah marilah kita bahas.
Soal :
Penyelesaikan :
Soal :
Penyelesaikan :
package latihan.pkg5.percabangan; import java.util.Scanner; public class Latihan5_Percabangan { public static void main(String[] args) { int pilihan; int j_mobil; int t_mobil; int j_motor; int t_motor; Scanner input = new Scanner(System.in); System.out.print("Masukan Pilihan Anda : "); pilihan = input.nextInt(); switch(pilihan){ case 1 : System.out.println("Mobil"); System.out.println("Mobil Jenis :"); j_mobil = input.nextInt(); if(j_mobil == 1){ System.out.println("Mobil Truck"); System.out.println("Jenis Mobil Truck : "); t_mobil = input.nextInt(); switch(t_mobil){ case 1 : System.out.println("Truck Puso"); break; case 2 : System.out.println("Truck Mini"); break; } } else if(j_mobil == 2){ System.out.println("Mobil Sedan"); System.out.println("Jenis Mobil Sedan : "); t_mobil = input.nextInt(); switch(t_mobil){ case 1 : System.out.println("Jazz"); break; case 2 : System.out.println("Pajero"); break; } } break; case 2 : System.out.println("Motor"); System.out.println("Motor Jenis :"); j_motor = input.nextInt(); if(j_motor == 1){ System.out.println("Motor Matic"); System.out.print("Jenis Motor Matic : "); t_motor = input.nextInt(); switch(t_motor){ case 1 : System.out.println("Beat"); break; case 2 : System.out.println("Vario"); break; } } else if(j_motor == 2){ System.out.println("Motor kOpling"); System.out.print("Jenis Motor kopling : "); t_motor = input.nextInt(); switch(t_motor){ case 1 : System.out.println("RX-KING"); break; case 2 : System.out.println("Ninja"); break; } } break; } } }Hasil :
No comments:
Write comments