import java.util.*;
class Conversion
{
public static void main(String args[])
{
int rem,inc=1,sum=0;
System.out.println("Enter Decimal No.");
Scanner f=new Scanner(System.in);
int num=f.nextInt(); //input as a decimal no.
while(num>0)
{
rem=num%2;
num=num/2;
sum=sum+rem*inc;
inc*=10;
}
System.out.println("Binary no. is "+sum); //Output as binary no.
}
}
class Conversion
{
public static void main(String args[])
{
int rem,inc=1,sum=0;
System.out.println("Enter Decimal No.");
Scanner f=new Scanner(System.in);
int num=f.nextInt(); //input as a decimal no.
while(num>0)
{
rem=num%2;
num=num/2;
sum=sum+rem*inc;
inc*=10;
}
System.out.println("Binary no. is "+sum); //Output as binary no.
}
}
No comments:
Post a Comment