Java program to convert a decimal number to binary number and vice versa. - BSC IT PRACTICALS

Monday, January 15, 2018

Java program to convert a decimal number to binary number and vice versa.


CODE:    
 
import java.util.*;
class prac2B
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("Enter the Decimal number ");
int no=input.nextInt();
int i=0;
int arr[]=new int[100];
while(no>0)
{
arr[i++]=no%2;
no=no/2;
}
System.out.print("Binary number are: ");
for(int j=i-1;j>=0;j--)
{
System.out.print(arr[j]);
}
}

}

No comments:

Post a Comment