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

 /* 

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

Input Data:

Input a Decimal Number : 5

Expected Output

Binary number is: 101 

*/

import java.util.*;


class Nine

{

public static void main(String arg[])

{

Scanner obj = new Scanner(System.in);

int i=0,x,no,y;


System.out.print("\nEnter any decimal value to convert it into Binary: ");

no = obj.nextInt();


int arr[] = new int[100];


if(no != 0)

{

do

{

x = no / 2;

arr[i] = no % 2;

no = x;

i++;

}

while(no != 0);


}

else

{

System.out.println("Enterd number is Zero");

}


System.out.print("\nBinary is : ");

for(int z=i-1 ; z>=0 ;z--)

{

System.out.print ("" + arr[z]);

}

}

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel



Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.