Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- ArrayDeque<Integer> binaryStack = new ArrayDeque<>();
- int decimal = sc.nextInt();
- String binary = "";
- if (decimal == 0) {
- binary = "0";
- } else {
- while (decimal != 0) {
- binaryStack.push(decimal % 2);
- decimal /= 2;
- }
- while(!binaryStack.isEmpty()) {
- binary += binaryStack.pop();
- }
- }
- System.out.print(binary);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement