package Praktek1;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class konversi_bilangan {
static String name;
static int bilDes;
static int asli;
public static void Biner(int n){
if(n>1){
Biner(n/2);
}
System.out.print(n%2);
}
public static void tampilBiner(){
inputDes();
System.out.print("Binernya adalah :");
Biner(bilDes);
}
public static void Oktal(int n){
if(n>1){
Oktal(n/8);
}
System.out.print(n%8);
}
public static void tampilOktal(){
inputDes();
System.out.print("Oktalnya adalah :");
Oktal(bilDes);
}
public static void Heksa(int n){
asli = n;
if(n>1){
Heksa(n/16);
}
if(!((n%16==0)&(n==asli))){
switch(n%16){
case 10 : System.out.print("A"); break;
case 11 : System.out.print("B"); break;
case 12 : System.out.print("C"); break;
case 13 : System.out.print("D"); break;
case 14 : System.out.print("E"); break;
case 15 : System.out.print("F"); break;
default : System.out.print(n%16);
}
}
}
public static void tampilHeksa(){
inputDes();
System.out.print("Heksanya adalah :");
Heksa(bilDes);
}
public static int inpBil(){
System.out.println("=================================="+
"\n\nSelamat datang "+name);
System.out.println("Silakan memilih Menu Konversi Bilanagn"+
"\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 inputDes() {
System.out.print("Masukkan Bilangan desimal = ");
Scanner inputan=new Scanner(System.in);
bilDes=inputan.nextInt();
}
public static void menU(int pil){
System.out.println("\033");
switch(pil){
case 1: tampilBiner(); break;
case 2: tampilHeksa();break;
case 3: tampilOktal();break;
case 4: System.out.println("BUBYE!!");
System.exit(0); break;
default:System.out.println("(Maaf. Pilih angka 1-4");
}
System.out.println("\033");
}
public static void main(String arg[]){
name = JOptionPane.showInputDialog("Masukkan Nama Anda ");
do{
menU(inpBil());
}
while(true);
}
}
Hasilnya OM :
Tidak ada komentar:
Posting Komentar