Advertisement
Guest User

Number Randomizer and Sorter (if even or odd)

a guest
Oct 7th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. Scanner input = new Scanner (System.in);
  2.        
  3.         System.out.println("Welcome to the number sorter!");
  4.        
  5.         System.out.println("The first number you enter must be smaller than the second number you enter.");
  6.        
  7.         System.out.print("Please enter a number between 0-99: ");
  8.         double fint = input.nextDouble();
  9.        
  10.         if (fint >= 0 && fint <= 99) {
  11.        
  12.             System.out.print("Now, enter another number between 0-99: ");
  13.             double sint = input.nextDouble();
  14.            
  15.             System.out.println("Okay, so the range is between " + fint + " and " + sint + ".");
  16.            
  17.             System.out.println("Still working on it...");
  18.            
  19.             double randomNum1 = fint + (int)(Math.random() * sint);
  20.            
  21.             double randomNum2 = fint + (int)(Math.random() * sint);
  22.              
  23.             double randomNum3 = fint + (int)(Math.random() * sint);
  24.            
  25.             System.out.println("Here are your random numbers:");
  26.            
  27.             System.out.println(randomNum1);
  28.          
  29.             System.out.println(randomNum2);
  30.            
  31.             System.out.println(randomNum3);
  32.            
  33.             double rNum1 = randomNum1 % 2;
  34.            
  35.             double rNum2 = randomNum2 % 2;
  36.            
  37.             double rNum3 = randomNum3 % 2;
  38.            
  39.            
  40.             System.out.println(rNum1 == 0);
  41.            
  42.             System.out.println(rNum2 == 0);
  43.            
  44.             System.out.println(rNum3 == 0);
  45.            
  46.                 } else {
  47.        
  48.             System.out.println("That number is not between 0-99.");
  49.            
  50.             System.out.print("Please enter a number between 0-99: ");
  51.            
  52.             double fint2 = input.nextDouble();
  53.                    
  54.            
  55.             if (fint2 >= 0 && fint2 <= 99) {
  56.                
  57.             System.out.print("Now, enter another number between 0-99: ");
  58.             double sint2 = input.nextDouble();
  59.            
  60.             System.out.println("Okay, so the range is between " + fint2 + " and " + sint2 + ".");
  61.            
  62.             System.out.println("Still working on it...");
  63.            
  64.             double randomNum1_2 = fint2 + (int)(Math.random() * sint2);
  65.            
  66.             double randomNum2_2 = fint2 + (int)(Math.random() * sint2);
  67.              
  68.             double randomNum3_2 = fint2 + (int)(Math.random() * sint2);
  69.             System.out.println("Here are your random numbers:");
  70.            
  71.             System.out.println(randomNum1_2);
  72.          
  73.             System.out.println(randomNum2_2);
  74.            
  75.             System.out.println(randomNum3_2);
  76.            
  77.            
  78.             } else {
  79.                 System.out.println("I told you to enter a number between 0-99, but you didn't...");
  80.                 System.out.println("So now this program is shutting down.");
  81.                 System.out.println("Goodbye!");
  82.                
  83.              }
  84.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement