title: How to implement a recursive method for converting an integer to binary representation
body: <p>I am writing a method to recursively convert an integer value to its binary representation.</p>
  <p>The code that I wrote below accomplishes the task by just using a method, but I'd like to know how to actually write out a full method.</p>
  <pre><code>import java.util.Scanner;
  
  public class Exercise18_21 {
  
      public static void main(String args[]){
          Scanner input = new Scanner(System.in);
          System.out.print(&quot;Enter a decimal integer: &quot;);
          int decimal    = input.nextInt();
          System.out.print(&quot;Enter a character: &quot;);
  
          System.out.printf(&quot;%d decimal is binary %s&quot;,decimal,dec2Bin(decimal));
      }
  
      //input: integer
      //output: binary representation of integer as a string
      public static String dec2Bin(int decimal){
          return Integer.toBinaryString(decimal);
      }
  
  }
  </code></pre>
  <p>My question is how can this be accomplished with recursion?</p>