Convert Decimal to Binary Program in Java


Prev Tutorial Next Tutorial

Convert Decimal to Binary Example in Java

This code is design using two methods, create own logic and use predefined method. Binary number system contain only two digits 0 and 1 and it have base 2.

Decimal Number representation of a real number using the base ten and decimal notation.

Binary Number contains only 0 and 1.

Convert Decimal to Binary in Java

import java.util.Scanner;
import java.util.Stack;

public class DecimalTObinary 
 public static void main(String[] args) 
Scanner in = new Scanner(;
// Create Stack object
Stack<Integer> stack = new Stack<Integer>();
//Take  User input from keyboard
 System.out.println("Enter any Decimal Number: ");
 int num = in.nextInt();
while (num != 0)
   int d = num % 2;
   num /= 2;
 System.out.print("\nBinary is:");
while (!(stack.isEmpty() ))


Enter any Decimal Number: 
Binary is: 111

Syntax to compile and run java program


for compile -> c:/>javac
for run -> c:/>java DecimalTObinary

Prev Tutorial Next Tutorial


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements

Buy Websites 9999595223
wifi cctv camera

Wifi CCTV Camera RS:1200 to 2499. Contact no. 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: or 9999595223 Try this Keyword C++ Programs