Enter any integer number as an input. After that we pass the given number to the other function where by using modulo operator along with recursion we get the reverse of a number as an output.
Here is the source code of the Java Program to Print Binary Equivalent of an Integer using Recursion. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Binary_Recursion
public static void main(String args)
Scanner s = new Scanner(System.in);
System.out.print("Enter the number:");
n = s.nextInt();
Binary_Recursion obj = new Binary_Recursion();
String m = obj.Binary(n);
String Binary(int x)
if(x > 0)
int a = x % 2;
x = x / 2;
return a + "" + Binary(x);
$ javac Binary_Recursion.java $ java Binary_Recursion Enter the number:19 Answer:11001
Sanfoundry Global Education & Learning Series – 1000 Java Programs.