Tech Study

Java Program To Convert a Decimal Number To Binary

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.Scanner;
public class Javaexcercise {
      public static void main(String args[])
    {
        int decimalnum, quot, i=1, j;
        int bin_num[] = new int[100];
        Scanner scan = new Scanner(System.in);
 
        System.out.print("Enter a Decimal Number : ");
        decimalnum = scan.nextInt();
 
        quot = decimalnum;
 
        while(quot != 0)
        {
            bin_num[i++] = quot%2;
            quot = quot/2;
        }
 
        System.out.print("Binary number is: ");
        for(j=i-1; j>0; j--)
        {
            System.out.print(bin_num[j]);
        }
        System.out.print("\n");
    }
}

Result

Write a Java program to convert a decimal number to binary numbers
Write a Java program to convert a decimal number to binary numbers

Write a Java program to count the letters, spaces, numbers and other characters of an input string

Write a java program to print numbers from 1 to 10 using loop

TaggedWrite a Java program to convert a decimal number to binary numbers

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more