0% found this document useful (0 votes)
30 views4 pages

Praktek Switch Case Menjadi IF Else

The document contains 5 Java programs that use if/else conditional statements to output different messages based on user input. Each program prompts the user to input some value and then uses if/else blocks to check that value and print a corresponding message to the console. The programs demonstrate using if/else statements to check string, character, and integer values for traffic light colors, grades, messages, days of the week, and ages.

Uploaded by

rijki010101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Praktek Switch Case Menjadi IF Else

The document contains 5 Java programs that use if/else conditional statements to output different messages based on user input. Each program prompts the user to input some value and then uses if/else blocks to check that value and print a corresponding message to the console. The programs demonstrate using if/else statements to check string, character, and integer values for traffic light colors, grades, messages, days of the week, and ages.

Uploaded by

rijki010101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

Scanner;

public class if1 {

public static void main(String[] args) {

String lampu;

Scanner scan = new Scanner(System.in);

System.out.print("Inputkan nama warna(merah,kuning,hijau): ");

lampu = scan.nextLine();

if(lampu.equals("merah")){

System.out.println("Lampu merah, berhenti!");

}else if(lampu.equals("kuning")){

System.out.println("Lampu kuning, harap hati-hati!");

}else if(lampu.equals("hijau")){

System.out.println("Lampu hijau, silahkan jalan!");

}else{

System.out.println("Warna lampu salah!");

import java.util.Scanner;

class if2 {

public static void main(String args[]){

char nilai;

Scanner input = new Scanner(System.in);

System.out.print("Input Nilai Anda (A - E): ");

nilai = input.next().charAt(0);

if(nilai=='A') {

System.out.println("Pertahankan!");

}else if(nilai=='B'){

System.out.println("Harus lebih baik lagi");


}

else if(nilai=='C'){

System.out.println("Perbanyak belajar");

}else if(nilai=='D'){

System.out.println("Jangan keseringan main");

else if(nilai=='E'){

System.out.println("Kebanyakan bolos...");

else{

System.out.println("Maaf, format nilai tidak sesuai");

import java.util.Scanner;

public class if3{

public static void main(String[] args)

String pesan ;

Scanner scan = new Scanner(System.in);

System.out.print("Inputkan Pesan satu, dua atau tiga: ");

pesan = scan.nextLine();

if(pesan.equals("satu")){

System.out.println("Selamat");

else if(pesan.equals("dua")){

System.out.println("Belajar");

else if(pesan.equals("tiga")){
System.out.println("Java");

else{

System.out.println("tidak ditemukan");

public class if4 {

public static void main(String args[])

int usia = 19 ;

if (usia==5){

System.out.println("Umur anda dibawah 19 tahun.");

else if(usia==19){

System.out.println("Anda sudah cukup umur");

else {

System.out.println("Mohon masukkan umur anda kembali.");

import java.util.Scanner;

public class if5 {

public static void main(String[] args) {

int hari;

Scanner input=new Scanner(System.in);


System.out.print("Input hari dalam angka (1 - 7): ");

hari=input.nextInt();

if(hari==1) {

System.out.println("Senin");

else if(hari==2){

System.out.println("Selasa");

else if(hari==3){

System.out.println("Rabu");

else if(hari==4){

System.out.println("Kamis");

else if(hari==5){

System.out.println("Jumat");

else if(hari==6){

System.out.println("Sabtu");

else if(hari==7){

System.out.println("Minggu");

You might also like