Sunday, March 11, 2018

Decimal to binary

Decimal to Binary
Send Feedback

Given a decimal number (integer N), convert it into binary and print.

The binary number should be in the form of an integer.

Note : The given input number could be large, so the corresponding binary number can exceed the integer range. So take the answer as long.

Input format :
Integer N
Output format :
Corresponding Binary number (long)
Sample Input 1 :
12
Sample Output 1 :
1100
Sample Input 2 :
7
Sample Output 2 :
111

import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{

Scanner s = new Scanner(System.in);
int n = s.nextInt();
System.out.println(Integer.toBinaryString(n));


}


}

No comments:

Post a Comment