Convert Decimal to Binary. (using recursion)

Convert Decimal to Binary. (using recursion)

Solution:Decimal to Binary Conversion Methods - Examples & Explanation ...

import java.util.*;

public class DecimalToBinary {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner sc= new Scanner(System.in);
System.out.println("Enter a valid integer:");

while(sc.hasNextInt())
{
int a=sc.nextInt();

printbinary(a);
System.out.println("\nEnter a bumber, press q to exit!");
}

sc.close();
}

public static void printbinary(int b)
{
if(b>0)
{
printbinary(b/2);
System.out.printf("%d", b%2);
}
}

}

Comments

Popular posts from this blog

Priority Scheduling Algorithm Java Program.

Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming).

Implement a class CppArray which is identical to a one-dimensional C++ array (i.e., the index set is a set of consecutive integers starting at 0) except for the following : 1. It performs range checking. 2.It allows one to be assigned to another array through the use of assignment operator. 3.It supports a function that returns the size of the array.