Konversi Desimal ke Biner dengan Java

package JavaApplication2;

class Rekursi {
void DesimalkeBiner(int n) {
if (n>1) {
DesimalkeBiner(n/2);
}
System.out.print(n%2);
}
}

class main{
public static void main(String[]args) {

Rekursi obj = new Rekursi();

System.out.println(“Bentuk biner dari 1 : “);
obj.DesimalkeBiner(1);
System.out.println();

System.out.println(“Bentuk biner dari 2 : “);
obj.DesimalkeBiner(2);
System.out.println();

System.out.println(“Bentuk biner dari 4 : “);
obj.DesimalkeBiner(4);
System.out.println();

System.out.println(“Bentuk biner dari 6 : “);
obj.DesimalkeBiner(6);
System.out.println();

System.out.println(“Bentuk biner dari 8 : “);
obj.DesimalkeBiner(8);
System.out.println();

System.out.println(“Bentuk biner dari 10 : “);
obj.DesimalkeBiner(10);
System.out.println();
}
}

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

%d bloggers like this: