Rabu, 05 September 2012

Convert numbers decimal with Java

Welcome to my blog.Back again with my post
This time I will give java post interesting lessons
so check this out ..
convert decimal numbers with java --->


step one, please look coding above
use application the name is Net beans
chect this out....

package Praktek1;

import java.util.Scanner;
import javax.swing.JOptionPane;

public class latihan_konvers {
    //global variable
    static String name;//object
    static String kelamin;
    static int bilDes;//variable

    //fingsi/method rekursi
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'};
    int sisaBagi = n%16;
    if(n>0){
        Hexa((n - sisaBagi) / 16);
    }
    System.out.print(daftarHexa[n%16]);
}
public static void Oktal(int n){
    char[] daftarOktal={'0','1','2','3','4','5','6','7'};
    int sisaBagi = n %8;
    if(n>0){
        Oktal((n - sisaBagi) / 8);
        System.out.print(daftarOktal[n%8]);
    }
}
public static void 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("\033");//clear screen
    switch(pil){
        case 1: tampilBiner(); break;
        case 2: tampilHexa(); break;
        case 3: tampilOktal(); break;
        case 4: System.out.println("Kamsia ya, sudah mampir.");
                System.exit(0); break;//memberikan kondisi FALSE
        default:System.out.println("(Maaf. Pilih angka 1-4 saja!)");
        break;
    }
    System.out.println("\033");//clear screen
}
public static void main(String arg[]){
    name=JOptionPane.showInputDialog("Masukkan nama Anda : ");//menampilkan input dialog untuk memasukkan nama
    //menampilkan Option Dialog untuk memilih jenis kelamin
        String[] choices = {"Perempuan", "Laki-Laki", "WARIA"};

        String Perempuan= "Mbak";
        String Laki= "Mas";
        while (true) {
            int response = JOptionPane.showOptionDialog(
                               null
                             , "Apa jenis kelamin Anda ?"
                             , "Jenis Kelamin"
                             , JOptionPane.YES_NO_OPTION
                             , JOptionPane.QUESTION_MESSAGE
                             , null
                             , choices
                             , "Quit"
                           );
        switch(response){
            case 0 : kelamin = Perempuan;
                break;
            case 1 : kelamin = Laki;
                break;
            case 2:
                System.out.println("maaf gak bisa kalo gak laki laki atau perempuan,silahkan melakukan penetapan kelamin!! ");
                     System.exit(0); break;
        }
    do{
        menU(inpBil());
    }
    while(true);
        }
}
}

                                    click shift+f6. then...

enter your name

choose your gender , for example, "Laki-laki"

If you click on one of the man will appear :


Example write the numbers 1, as shown :


Then insert the decimal number :
and will see the results of binary


To exit, content with the number 4:


and finish ..
That was my post, maybe useful if there is a lack of forgiveness.







Tidak ada komentar:

Posting Komentar