Contoh Penggunaan Switch-Case

October 8, 2010

Berikut akan diberikan contoh penggunaan Swtich-Case di java. :mrgreen:

import java.util.Scanner;

public class SwitchCase {
	public static void main(String args[]){
		System.out.print("Masukkan angka: 1, 2, atau 3: ");
		
		Scanner str = new Scanner(System.in);
		int strInt = str.nextInt();
				
		switch(strInt){
			case 1 : System.out.println("Anda memilih:" + strInt);
				break;
			case 2 : System.out.println("Anda memilih:" + strInt);
				break;
			case 3 : System.out.println("Anda memilih:" + strInt);
				break;
			default : System.out.println("Anda tidak memilih 1,2, atau 3.");
		}
		
	}

}

hasilnya:

About these ads

2 Responses to “Contoh Penggunaan Switch-Case”

  1. Jabmoppydoomi Says:

    Przeczytaj caly blog jest bardzo dobry

  2. emy Says:

    A good reference for the task


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: