/*********************************************************************************
* (Decimal to binary) Write a recursive method that converts a decimal number    *
* into a binary number as a string. The method header is:                        *
*                                                                                *
* public static String dec2Bin(int value)                                        *
*                                                                                *
* Write a test program that prompts the user to enter a decimal number and       *
* displays its binary equivalent.                                                *
*********************************************************************************/
import java.util.Scanner;

public class Exercise_18_21 {
	/** Main method */
	public static void main(String[] args) {
		// Create a Scanner
		Scanner input = new Scanner(System.in);

		// Prompt the user to enter a decimal number
		System.out.print("Enter a decimal number: ");
		int value = input.nextInt();

		// Display the value's binary equivalent
		System.out.println("The binary equivalent of " 
			+ value + " is " + dec2Bin(value));
	}

	/** Methods converts a decimal number
	  * into a binary number as a string */
	public static String dec2Bin(int value) {
		String result = "";
		return dec2Bin(value, result);
	}

	/** Recursive helper method */
	public static String dec2Bin(int value, String result) {
		if (value / 2 == 0)
			return (value % 2) + result;
		else
			return dec2Bin(value / 2, (value % 2) + result);
	}
}
@@ -1480,16 +1480,29 @@
  2 == 0)
+ // Base case
 %0A%09%09%09retu
@@ -1580,17 +1580,35 @@
 ) + result);
+ // Recursive call
 %0A%09%7D%0A%7D

Add Ex 18.21