Write a program to convert decimal
to binary number.
Write java code Convert decimal number to binary number.
import
java.io.*;
public
class decimal2binary {
public static void
main(String[]args)throws IOException {
int num,i=0,k,j;
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter
the decimal number to convert into binary:- ");
num=Integer.parseInt(br.readLine());
int a[]=new int[20];
int b[]=new int[20];
while(num>0) {
a[i]=num%2;
i++;
num=num/2;
}
k=i-1;
System.out.print("\n");
for(j=0;j<i;j++) {
b[j]=a[k];
System.out.print(b[j]);
k--;
}
}
}
No comments:
Post a Comment