Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Saturday, 30 December 2017

java program to convert decimal to binary

import java.util.Scanner;
public class DeciToBin

public static void main(String[] args) 
{     
int decimal, rem, quotient, i=1, j;
int binary[] = new int[100];
Scanner sc = new Scanner(System.in);
System.out.print("Enter any Decimal Number : ");
decimal = sc.nextInt();       
quotient = decimal;       
while(quotient != 0)     
{         
binary[i++] = quotient%2;         
quotient = quotient/2;     
}       
System.out.print("Equivalent Binary Value of " + deciaml + " is :\n");     
for(j=i-1; j>0; j--)     
{         
System.out.print(binary[j]);     

}
}

No comments:

Post a Comment