Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This project's purpose is to try and find the cure for covid
- * The program will randomly create phrases until it finds "the cure for covid"
- * Madeline Boese
- * 10/4/20
- * */
- //Import random class
- import java.util.Date;
- import java.util.Random;
- public class Main {
- public static void main (String args[]) {
- //Create number int for later use in random
- int number = 0;
- //Create phrase String for later use as phrase
- String phrase = "";
- //While loop to check if the phrase is "the cure for covid"
- while (phrase != "the cure for covid") {
- //Check phrase, then reset it
- System.out.println(phrase);
- phrase = "";
- //for loop to get 19 random characters
- //Recursion 2 of 2
- for (int i=1; i<=19; i++) {
- //Create an instance of the random class
- Random rand = new Random();
- //Create a date class for truly random numbers
- Date date = new Date();
- //Get a truly random number
- long time = date.getTime();
- int fixedTime = (int)time;
- if (fixedTime <=0) { //Need to make sure fixedTime is a positive integer
- fixedTime *= -1;
- fixedTime += 1;
- }
- //Get the random number
- number = rand.nextInt(fixedTime);
- number %= 27;
- //Use the random number to generate a character
- if (number == 0) {
- phrase += " ";
- }
- else if (number <= 25 && number>=1) {
- phrase += (Character.toString((char)(number+97)));
- }
- }
- }
- //Print out our answer at the end.
- System.out.println('\n'+phrase);
- System.out.println("I can't believe it did it!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment