daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class Binary
  3. {
  4.     public static void main (String[]args){
  5.     int n;
  6.     int counter = 1;
  7.     Scanner scan = new Scanner(System.in);
  8.  
  9.     System.out.println ("Please a sequence of 1's and 0's");
  10.     n= scan.nextInt();
  11.  
  12.     for (int index = 0; index < n.length();
  13.     index++) {
  14.     char aChar = n.charAt(index);
  15.     }
  16.  
  17.     if (n < 0 || n > 1) {        //base case
  18.         System.out.println ("Error. Please enter 1 or 0");
  19.         n = scan.nextInt();}
  20.     else if (n < 2){  //base case
  21.         System.out.print(n);
  22.         return;}
  23.     else {
  24.         n = (n/2);   //recursive step
  25.         int answer = n%2;  
  26.         System.out.print(answer);}
  27.  
  28. }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top