Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Help with CompSci project?
So I'm working on a project for CompSci. The project is basically to create a game where the computer chooses a letter (W, X, Y, or Z) four times and the person that runs the program has to guess the word. It would tell you how many letters you got correct and how many guesses you have left.
Right now, I'm trying to make the computer generate the four-letter sequence. I did the code as such (ignore the earlier code as I did it correctly):
String word;
for (int x = 0; x < 4; x++) {
x = rand.nextInt(4);
The problem is when I tried to compile the code, it says the int cannot be dereferenced. I looked up what this issue means and it seems like I'm using int when I shouldn't be, but I can't see what the problem is.
I don't know if the problem is that I'm using the for loop incorrectly or if I don't quite understand the rand.nextInt() part. Any assistance would be excellent.
2 Answers
- EddieJLv 71 year ago
<x> is the index of your <for> loop.
That mean it will be 0, then 1, then 2, then 3.
Why are you trying to assign a random number to <x>?
You didn't show your entire <for> loop. Where are you forming the word?
- DeMoNsLaYeR575Lv 71 year ago
you are setting X in the for loop then trying to assign it the rand.nextint.
change the rand.nextint variable to something else and initialize it like this int nxt = ran.nextInt(4);