Guest User

The Cure For COVID Reddit

a guest
Oct 4th, 2020
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. /*
  2.  * This project's purpose is to try and find the cure for covid
  3.  * The program will randomly create phrases until it finds "the cure for covid"
  4.  * Madeline Boese
  5.  * 10/4/20
  6.  * */
  7.  
  8.  
  9. //Import random class
  10. import java.util.Date;
  11. import java.util.Random;
  12. public class Main {
  13.  
  14.     public static void main (String args[]) {
  15.        
  16.         //Create number int for later use in random
  17.         int number = 0;
  18.         //Create phrase String for later use as phrase
  19.         String phrase = "";
  20.        
  21.         //While loop to check if the phrase is "the cure for covid"
  22.         while (phrase != "the cure for covid") {
  23.             //Check phrase, then reset it
  24.             System.out.println(phrase);
  25.             phrase = "";
  26.             //for loop to get 19 random characters
  27.             //Recursion 2 of 2
  28.             for (int i=1; i<=19; i++) {
  29.             //Create an instance of the random class
  30.                 Random rand = new Random();
  31.                 //Create a date class for truly random numbers
  32.                 Date date = new Date();
  33.                
  34.                 //Get a truly random number
  35.                 long time = date.getTime();
  36.                 int fixedTime = (int)time;
  37.                 if (fixedTime <=0) { //Need to make sure fixedTime is a positive integer
  38.                     fixedTime *= -1;
  39.                     fixedTime += 1;
  40.                 }  
  41.                 //Get the random number
  42.                 number = rand.nextInt(fixedTime);
  43.                 number %= 27;
  44.                
  45.                 //Use the random number to generate a character
  46.                 if (number == 0) {
  47.                     phrase += " ";
  48.                 }  
  49.                 else if (number <= 25 && number>=1) {
  50.                     phrase += (Character.toString((char)(number+97)));
  51.             }
  52.         }
  53.         }
  54.         //Print out our answer at the end.
  55.         System.out.println('\n'+phrase);
  56.         System.out.println("I can't believe it did it!");
  57.        
  58.     }
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment