my program first says:
As we know if you could only pick a number
out of 1 million your chances are 1 in 1 million:
today I am going to prove this...I hope
you can pick a number from 2 to 10000000000000000000 ish <-- this is the number Range
then you pick a number you want to come up
and how many times you wish for it to occur
password is abc123... incase you can't find it
bug free i hope
/* made by James Anderson *version 0.1.6 alpha *V 0.1.6 can occurs a number of times *V 0.1.5 changed name from lotto3 to RandomNumbers.java *V 0.1.4 (added password for fun) */ import java.util.Scanner; import java.util.Random; public class RandomNumbers { public static void main (String[] args) { Scanner myScanner = new Scanner(System.in); Random myRandom = new Random(); int RandomNumber = 0, UserNumber = 0, givennumber=0, TotalNumbers = 0, NumberOfTimes=0,InputNumberOfTimes = 0; String Password = "abc123", userinput; System.out.println ("version 0.1.5"); //password System.out.print ("please type in the password: "); userinput = myScanner.nextLine(); if (Password.equalsIgnoreCase(userinput)){ System.out.println ("Right Password."); System.out.println (); //explan to user System.out.println ("As we know if you could only pick a number"); System.out.println ("out of 1 million your chances are 1 in 1 million:"); System.out.println ("today I am going to prove this...I hope"); System.out.println (); //totalnumber setup do{ System.out.print("Pick a maximum number (larger numbers take longer): "); System.out.println ("must be greater than 1"); TotalNumbers = myScanner.nextInt(); }while(TotalNumbers < 2); //example of a number and explaning to pick a number givennumber = (myRandom.nextInt(TotalNumbers) + 1); System.out.println("Pick a number between 1 and " + Integer.toString(TotalNumbers) + " (for example " + Integer.toString(givennumber) + "): "); System.out.println("Bad responses will be forced to reenter:"); //user picks a number do{ UserNumber = myScanner.nextInt(); if (UserNumber > TotalNumbers) { System.out.println ("Must be less than " + TotalNumbers + " Please type again:"); } else if (UserNumber < 1){ System.out.println ("must be greater than 0 Please type again:" ); } }while(UserNumber < 1 || UserNumber > TotalNumbers); // number of times System.out.println ("how many times would you like it to occur?"); InputNumberOfTimes = myScanner.nextInt(); //run System.out.println (); System.out.println (); for (int times=0; (RandomNumber != UserNumber);) { do { //reset RandomNumber = -1; for (; (RandomNumber != UserNumber); times ++){ RandomNumber = (myRandom.nextInt(TotalNumbers) + 1); System.out.println (RandomNumber); } NumberOfTimes++; } while (NumberOfTimes != InputNumberOfTimes); //finish System.out.println (); System.out.print ("It took "); System.out.print (times); System.out.println (" times until your number came up; "+ NumberOfTimes +" times."); System.out.println ("With: " + (TotalNumbers) + " likely numbers that could pop up (this is not fake)"); System.out.println ("Can you believe it...want to try again?"); } } else { System.out.println ("Sorry Wrong password"); } } }