- Pertama buka NetBeans kalian
- Kemudian klik kanan pada package lalu New-Java
Class
- Kemudian ketik kode berikut :
/*
* To change this template, choose
Tools | Templates
* and open the template in the
editor.
*/
package praktek.pkg1;
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
*
* @author user
*/
public class nyobak {
static String name;
static int bilDes;
static String kelamin;
public static void Biner(int n){
if(n>1){
Biner(n/2);
}
System.out.print(n%2);
}
public static void Hexa(int n){
char[]
daftarHexa={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
if(n>1){
Hexa(n/16);
}
System.out.print(daftarHexa[n%16]);
}
public static void Oktal(int n){
char[]
daftarOktal={'0','1','2','3','4','5','6','7'};
if(n>1){
Oktal(n/8);
}
System.out.print(daftarOktal[n%8]);
}
public static int inputDes(){
System.out.print("Masukkan Bilangan desimal = ");
Scanner inputan=new
Scanner(System.in);
bilDes=inputan.nextInt();
return bilDes;
}
public static void tampilBiner(){
inputDes();
System.out.print("Binernya adalah ");
Biner(bilDes);
}
public static void tampilHexa(){
inputDes();
System.out.print("Hexanya adalah ");
Hexa(bilDes);
}
public static void tampilOktal(){
inputDes();
System.out.print("Oktalnya adalah ");
Oktal(bilDes);
}
public static int inpBil(){
System.out.println("===============================" +
"\nSelamat datang "+kelamin+", "+name+"");
System.out.println("Silahkan memilih Menu Konversi " + "Bilangan
ke: "+ "\n1. Biner \n2. Hexa \n3. Oktal \n4. Exit");
System.out.print("Masukkan Angka Menu = ");
Scanner inputan=new
Scanner(System.in);
int
pilmenu=inputan.nextInt();
return pilmenu;
}
public static void menU(int pil){
System.out.println("\003");
switch(pil){
case 1:
tampilBiner(); break;
case 2: tampilHexa();
break;
case 3:
tampilOktal(); break;
case 4:
System.out.println("Terima Kasih ya "+kelamin+"
"+name+", sudah mampir.");
System.exit(0); break;
default:System.out.println("(Maaf. Pilih angka 1-4 saja)");
break;
}
System.out.println("\003");
}
public static void main(String arg[]){
name=JOptionPane.showInputDialog("Masukkan Nama Anda :");
String [] options = {
"Cowok", "Cewek","Banci" };
String Cowok="Mas
Ganteng";
String Cewek="Mbak
cantik";
while(true){
int choice =
JOptionPane.showOptionDialog(
null,
"Kamu Cowok atau Cewek?",
"Jenis Kelamin",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, "Quit");
switch(choice){
case 0 : kelamin=Cowok;
break;
case 1 : kelamin=Cewek;
break;
default : kelamin="Banci ya? haha :p ";
}
do{
menU(inpBil());
}
while(true);
}
}
}
Tidak ada komentar:
Posting Komentar