import java.io.*;
class DectoBin
{
public static void main(String args[])
{
int i=0;
int bin[]=new int[10];
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter Decimal Number");
int dec=Integer.parseInt(cin.readLine());
while(dec>0)
{
bin[i]=dec%2;
dec=dec/2;
i++;
}
i--;
for(int j=i;j>=0;j--)
System.out.print(bin[j]);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class DectoBin
{
public static void main(String args[])
{
int i=0;
int bin[]=new int[10];
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter Decimal Number");
int dec=Integer.parseInt(cin.readLine());
while(dec>0)
{
bin[i]=dec%2;
dec=dec/2;
i++;
}
i--;
for(int j=i;j>=0;j--)
System.out.print(bin[j]);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
No comments:
Post a Comment