In this tutorial, we will write a program to convert a decimal number into binary in java using recursion. Before that, you must have knowledge of the following topics in java.
The binary numbers are based on 0 and 1, so it is a base 2 number. They are the combination of 0 and 1. For example, 1001, 110101, etc.
These are the numbers with a base of 10, which ranges from 0 to 9. These numbers are formed by the combination of 0 to 9 digits such as 24, 345, etc.
Here is the chart where for the equivalent value of decimal and binary numbers.
Now let us go through a program for the conversion of decimal to binary in java using recursive function.
Java Program to Convert Decimal to Binary using Recursion
public class Main
public static void main(String args)
Scanner in = new Scanner(System.in);
System.out.println("Enter a decimal number: ");
dec = in .nextInt();
System.out.print("Equivalent Binary Value: ");
System.out.println(conversionFunc(dec)); //calling recursive function
public static int conversionFunc(int decNumber)
if (decNumber == 0)
return (decNumber % 2 + 10* conversionFunc(decNumber / 2));
Enter a decimal number:
Equivalent Binary Value: 111
String Pattern Programs in C
Java Program to Find pair of Integers in Array whose sum is given Number
Program to Print Diamond Alphabet Patterns in C
Half Diamond Pattern in C using Alphabets
Half Pyramid of Alphabets in C