Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Problem 22

One comment on “Problem 22”


  • The Bong

    import java.util.Stack;

    public class DecimelToBinary {
    public static void main(String[] args) {
    System.out.println(decToBinary(50));
    }
    static String decToBinary(int num) {
    Stack stack = new Stack();
    String resString = “”;
    int temp = num;
    while (temp >= 1) {
    String remainder = String.valueOf(temp % 2);
    stack.push(remainder);
    temp /= 2;
    }
    while (!stack.isEmpty()) {
    resString += stack.peek();
    stack.pop();
    }
    return resString;
    }
    }