im writing a program where I have to have the computer randomly choose 1 of 10 objects that i have written down as a string array... im using the the math.random function to come up with a number...
int targetNumber = (int) (Math.random() * 10);
System.out.println("I'm thinking of an item, I will only choose one of 10...");
how do i link that randomly generated int to a string inside a string array with ten different items inside... first time doing java and a pretty big noob, keep failing at this part
public static String getElement(int x){
String[] stringArray = new String[10];
stringArray[0] = "Gold";
stringArray[1] = "Barnacle";
stringArray[2] = "Wenches";
stringArray[3] = "Wooden Leg";
stringArray[4] = "Davey Jones Locker";
stringArray[5] = "Keira Knightley";
stringArray[6] = "Capt. Sparrow's Sword";
stringArray[7] = "The Black Pearl";
stringArray[8] = "Davey Jones Heart";
stringArray[9] = "Diamonds";
return stringArray[x];
}
its pirates of the caribean themed... school work