Last active
April 11, 2018 04:10
-
-
Save justudin/bd59ce16bb74f77a75b00b1b0b6eaf45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
// main class DesToBin | |
public class DesToBin { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int des, a; | |
Konversi angka = new Konversi(); | |
//get input from user | |
Scanner input = new Scanner(System.in); | |
System.out.print("Masukkan Angka : "); | |
//assigned the input into des variable | |
des = input.nextInt(); | |
// print out the input | |
System.out.println("Bilangan Desimalnya : " + des); | |
//print out the result | |
System.out.print("Konversi Binernya : "); | |
angka.desimalkebiner(des); | |
//print out | |
System.out.println(); | |
} | |
} | |
// class for converting decimal to binary | |
class Konversi { | |
//public method for conversion with int param | |
public void desimalkebiner(int a) { | |
if (a > 1) { | |
desimalkebiner(a / 2); | |
} | |
//print out the result | |
System.out.print(a % 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment