Advertisement
deyanmalinov

03. Decimal To Binary

May 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args){
  7.         Scanner scan = new Scanner(System.in);
  8.         int num = scan.nextInt();
  9.         if (num == 0){
  10.             System.out.println(0);
  11.             return;
  12.         }
  13.         Deque<Integer> stack = new ArrayDeque<>();
  14.         while (num !=0){
  15.             stack.push(num % 2);
  16.             num /= 2;
  17.         }
  18.         for (Integer integer : stack) {
  19.             System.out.print(stack.pop());
  20.  
  21.         }
  22.  
  23.         }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement