Advertisement
LynchzDEV

RandomQuoteGeneratorButBetter

Aug 31st, 2023
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | Source Code | 0 0
  1. package playground;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. public class RandomQuoteGeneratorButBetter {
  7.     public static void main(String[] args) {
  8.         String[] quotes = {
  9.                 "The greatest glory in living lies not in never falling, but in rising every time we fall.",
  10.                 "The future belongs to those who believe in the beauty of their dreams.",
  11.                 "The way to get started is to quit talking and begin doing.",
  12.                 "Life is what happens when you're busy making other plans.",
  13.                 "The world is a book and those who do not travel read only one page.",
  14.                 "Life is either a daring adventure or nothing at all.",
  15.                 "Your time is limited, don't waste it living someone else's life.",
  16.                 "The purpose of our lives is to be happy.",
  17.                 "I find that the harder I work, the more luck I seem to have.",
  18.                 "Don't let yesterday take up too much of today."
  19.         };
  20.  
  21.         ArrayList<Integer> availableNumbers = new ArrayList<>();
  22.         for (int i = 1; i <= quotes.length; i++) {
  23.             availableNumbers.add(i);
  24.         }
  25.  
  26.         Random random = new Random();
  27.         for (int i = 0; i < quotes.length; i++) {
  28.             int randomIndex = random.nextInt(availableNumbers.size());
  29.             int selectedNumber = availableNumbers.remove(randomIndex);
  30.  
  31.             System.out.println("Randomly selected quote:");
  32.             System.out.println(quotes[selectedNumber - 1]);
  33.  
  34.             System.out.print("\nRemaining: ");
  35.             for (Integer number : availableNumbers) {
  36.                 System.out.print(number + ",");
  37.             }
  38.  
  39.             System.out.println("\nPress Enter to continue to the next quote...");
  40.             new java.util.Scanner(System.in).nextLine();
  41.             System.out.println("--------------------------------------");
  42.         }
  43.     }
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement