Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // HW
- import java.util.Scanner;
- public class DecToBinary {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- int dec;
- System.out.print("Enter a decimal number: ");
- dec = in.nextInt();
- System.out.println("The binary equivalent is:");
- for(int i = 7; i >= 0; i--)
- {
- if((dec / (int)(Math.pow(2, i))) % 2 == 1)
- System.out.print("1");
- else
- System.out.print("0");
- }
- in.close();
- }
- }
Add Comment
Please, Sign In to add comment