Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Digital2BinaryApp.java
Language: JAVA
Code:
import java.util.Stack; 
import java.util.Scanner;
 
public class Decimal2BinaryApp {
 
    public static void main (String args[]) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter decimal number = ");
        
        int num = input.nextInt();
        Stack<Integer> s = new Stack<Integer>();
        
        int n = num;
        
        while (n > 0) {
            s.push(n % 2);
            n = n / 2;
        }
        
        System.out.print(num + " converted to binary is ->  ");
        
        while (!(s.isEmpty())) {
            System.out.print(s.pop()+" ");
        }
        input.close();
    }
}
          
Comments: