Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DNS
- {
- public static void main(String[] args)
- {
- int y;
- Scanner input = new Scanner( System.in);
- do
- {
- System.out.println("java DisplayNumberSystems");
- System.out.println("Enter a decimal value to display to: ");
- y = input.nextInt();
- for(int x=0; x <=y; x++)
- {
- convertToBinary(x);
- }
- }
- while(y <=1024);
- }
- public static void convertToBinary(int x)
- {
- if(x >0)
- {
- convertToBinary(x/2);
- System.out.print(x%2 + " ");
- }
- System.out.println("");
- }
- }
- int y;
- Scanner input = new Scanner( System.in);
- System.out.println("java DisplayNumberSystems");
- System.out.println("Enter a decimal value to display to: ");
- y = input.nextInt();
- while(y <=1024)
- {
- for(int x=0; x <=y; x++)
- {
- convertToBinary(x);
- }
- }
- for (int x = 0; x <= y; x++) {
- convertToBinary(x);
- System.out.println();
- }
- while (true) {
- System.out.println("java DisplayNumberSystems");
- System.out.println("Enter a decimal value to display to: ");
- y = input.nextInt();
- if (y < 0) {
- System.out.println("That number is not positive!");
- break;
- }
- if (y > 1024) {
- System.out.println("That number is too big!");
- break;
- }
- for (int x = 0; x <= y; x++) {
- convertToBinary(x);
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment