welcome


Sabtu, 21 Desember 2013

Menu Switch Case pada JAVA



import javax.swing.*;
public class mymenu
{
public static void main (String args[])
{
do 
{
int pil=Integer.parseInt(JOptionPane.showInputDialog
("MENU\n 1. While\n 2. Deret\n 3.Nilai\n 4. Exit\n Masukkan Pilihan [1..4]"));
switch(pil)
{
case 1:
int nilai=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai : "));
while (nilai >= 1)
{
JOptionPane.showMessageDialog(null, "Aku Anak Soleh", 
"Output",JOptionPane.INFORMATION_MESSAGE);

nilai--;
}
System.out.println("\n");
break;

case 2:
int a=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Deret : "));
String gmbr = "Segitiga \n";
for(int i=1;i<=a;i++)
{
              for(int j=1;j<=i;j++)
              {
                  gmbr += "*"+" ";
              }
              gmbr += "\n";
              }
              gmbr +="\n";
            JOptionPane.showMessageDialog(null, gmbr, "Segitiga",JOptionPane.INFORMATION_MESSAGE);
           
           break;

case 3:
int kondisi=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai : "));
if (kondisi > 60)
{
JOptionPane.showMessageDialog(null, "Selamat Anda Lulus","Output",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null, "Maaf Anda Gagal","Output",JOptionPane.INFORMATION_MESSAGE);
}
System.out.println("\n");
break;
case 4:
System.exit(0);

default:
JOptionPane.showMessageDialog(null, "Silahkan Pilih Dari [1..4]", 
"Anda Salah Pilih",JOptionPane.WARNING_MESSAGE);

}
}
while(true);
}    
}

Tidak ada komentar:

Posting Komentar