I am new to Java and this is one of my first codes that I'm posting, its a 8ball that returns a random answer via the console. I was just wondering if there is anything on this code that I can improve to further my knowledge, any help would be great
import java.util.Scanner; public class 8ball { /** * Coded by Cody Reuille * */ public static void main(String[] args) throws InterruptedException { /** * adds Scanners to check if a question is asked and to see if you want * to ask another question */ Scanner question = new Scanner(System.in); Scanner repeat = new Scanner(System.in); // initiates the int used for the random number int rndoutcome; // while loop so you can ask more then one question without it // terminating while (true) { System.out.println("Please state you're question."); question.nextLine(); // sets rndoutcome to a random number 0-9 rndoutcome = (int) (Math.random() * 10); // switch statement for random outcomes switch (rndoutcome) { case 0: System.out.println("Nope."); break; case 1: System.out.println("Anything is possible!"); break; case 2: System.out.println("Never!"); break; case 3: System.out.println("Yes!"); break; case 4: System.out.println("Please try again later."); break; case 5: System.out.println("I dont feel like answering that..."); break; case 6: System.out.println("Not even in your dreams."); break; case 7: System.out.println("Whats the answer im looking for? oh, NO!"); break; case 8: System.out.println("Maybe someday, but not today."); break; case 9: System.out.println("This is correct."); break; } // 2 second pause before asking if you want to ask another question Thread.sleep(2000); System.out.println("Would you like to ask another question? (Yes/No)"); // checks to see if you enter yes or no if (!repeat.nextLine().equalsIgnoreCase("yes")) { // if you type yes then it will repeat, if not it will terminate break; } } } }