Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DecimalToBinary
- {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter a number (base 10): ");
- int num = sc.nextInt();
- int temp = num;
- String bin = "";
- while(temp > 0)
- {
- bin = (temp % 2) + bin;
- temp /= 2;
- }
- System.out.println("The binary for " + num + " is " + bin);
- }
- }
Add Comment
Please, Sign In to add comment