Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Scanner;
- public class DecimalToBinary {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int num = Integer.parseInt(sc.nextLine());
- ArrayDeque<Integer> stack = new ArrayDeque<>();
- if(num == 0){
- stack.push(0);
- }
- while (num != 0){
- int remain = num % 2;
- stack.push(remain);
- num /= 2;
- }
- for (int i = stack.size(); i > 0; i--) {
- System.out.print(stack.pop());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement