dimanche 4 novembre 2018

Creating Random Strings

// In the program for 8 balls, I was asked to output a random string when asked a yes or no question. So this is what I did

public class eightBall {

private static String[] randoms;


public static void main(String[] args) {
    String[] stringArray = {"Yes, of course","Without a doubt, Yes", "You can count on it", "For sure","Ask me later","I'm not sure", "I can't tell you right now","I'll tell you after my nap", "No way!","I don't think so", "Without a doubt no","The answer is clearly No"};    
    Random randoms = new Random();

    stringArray[randoms.nextInt(stringArray.length)];
    System.out.print(stringArray);
}

}

But the program doesn't work everytime I modified. Even searching online didn't help much with figuring out the solution.

Please help me solve this program. I'll be much appreciated.




Aucun commentaire:

Enregistrer un commentaire