import java.util.*;
class dectobin
{
public int n,m,s,i,a;
public void input()
{
Scanner br = new Scanner(System.in);
System.out.println(" Input anumber n");
n=br.nextInt();
}
public void calculate()
{
s=0;
i=0;
m=n;
while(n>0)
{
a=n%2;
s = s + (int)Math.pow(10,i)*a;
n=n/2;
i++;
}
System.out.println("Binary value for " + m + " is " + s);
}
public static void main(String arg[])
{
dectobin ob= new dectobin();
ob.input();
ob.calculate();
}
}
No comments:
Post a Comment