Decimal to Binary
12
1100
import java.util.Scanner;
public class DecToBin {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int binary[] = new int[100];
int index = 0;
if(n==0)
{
System.out.println("0");
}
while(n > 0)
{
binary[index++] = n%2;
n = n/2;
}
for(int i = index-1;i >= 0;i--)
{
System.out.print(binary[i]);
}
}
}
Comments
Post a Comment