Advertisement
willieshi232

Untitled

Apr 18th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Binary2{
  3.  
  4. public static void main(String[] args) {
  5.  
  6. int input;
  7. Scanner console = new Scanner(System.in);
  8.  
  9. System.out.print("Enter number to convert to binary: ");
  10. input = console.nextInt();
  11. Binary(input);
  12.  
  13. }
  14.  
  15. public static void Binary(int num) {
  16. if (num>0) {
  17. Binary(num/2);
  18. System.out.print(num%2 + " ");
  19. }
  20. }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement