dimanche 29 janvier 2017

Retrieve a string that was assigned into a random index inside of an array

So I need to locate where the "Nut" string is stored at. I thought my code would work just fine but obvious the ide just keep throwing me an error.

   Random rd = new Random();

    String[] hidingSpots = new String[100];

    hidingSpots[rd.nextInt(hidingSpots.length)] = "Nut";
    System.out.println("The nut has been hidden ...");

    int nutLocation = 0;

    while (nutLocation < hidingSpots.length) {
        if (hidingSpots[nutLocation].equals("Nut")) {
            System.out.println("Found it! It's in spot# " + hidingSpots[nutLocation]);
        }

        nutLocation++;

    }




Aucun commentaire:

Enregistrer un commentaire