daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class DNS
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         int y;
  8.         Scanner input = new Scanner( System.in);
  9.     do
  10.     {  
  11.         System.out.println("java DisplayNumberSystems");
  12.         System.out.println("Enter a decimal value to display to: ");
  13.         y = input.nextInt();
  14.  
  15.         for(int x=0; x <=y; x++)
  16.         {
  17.             convertToBinary(x);
  18.         }
  19.     }
  20.     while(y <=1024);    
  21.  
  22.     }
  23.  
  24.     public static void convertToBinary(int x)
  25.     {
  26.         if(x >0)
  27.         {
  28.             convertToBinary(x/2);
  29.             System.out.print(x%2 + " ");
  30.  
  31.         }
  32.         System.out.println("");
  33.     }
  34.  
  35. }
  36.    
  37. int y;
  38.     Scanner input = new Scanner( System.in);
  39.     System.out.println("java DisplayNumberSystems");
  40.     System.out.println("Enter a decimal value to display to: ");
  41.     y = input.nextInt();
  42.  
  43.     while(y <=1024)
  44. {  
  45.  
  46.     for(int x=0; x <=y; x++)
  47.     {
  48.         convertToBinary(x);
  49.     }
  50. }
  51.    
  52. for (int x = 0; x <= y; x++) {
  53.     convertToBinary(x);
  54.     System.out.println();
  55. }
  56.    
  57. while (true) {
  58.     System.out.println("java DisplayNumberSystems");
  59.     System.out.println("Enter a decimal value to display to: ");
  60.     y = input.nextInt();
  61.  
  62.     if (y < 0) {
  63.         System.out.println("That number is not positive!");
  64.         break;
  65.     }
  66.  
  67.     if (y > 1024) {
  68.         System.out.println("That number is too big!");
  69.         break;
  70.     }
  71.  
  72.     for (int x = 0; x <= y; x++) {
  73.         convertToBinary(x);
  74.         System.out.println();
  75.     }
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top