Based on the method descriptions below, how can I pass the Scanner from the main() method to the promptUserForSeed() method, and how can I use the long variable that the promptUserForSeed() method...
Type: Posts; User: dataghost
Based on the method descriptions below, how can I pass the Scanner from the main() method to the promptUserForSeed() method, and how can I use the long variable that the promptUserForSeed() method...
I think I've implemented the highlightWord() method correctly, I just need help now with passing the long variable "seed" from the promptUserForSeed() method into the findWords() method, and then...
I'm having trouble with a WordSearch project that I've been assigned.
Essentially, what I'm supposed to do is create a Java program that reads a word search grid from a class that has been written...
I've actually solved the problem of delayed print statements. A problem I have now is printing both characters in a string if said string happens to contain two identical characters, like character...
Thank you, I have displayWord storing old guesses as well as new ones, but when it prints displayWord after new guesses it is delaying the reveal of said guesses by one round.
This is the code I...
Could you explain to me how this code would update if I was entering a new number every time it ran? In that case '3' would have to be a variable to account for the user's input.
EDIT: Never mind,...
I completely forgot to place quotes around the digit in order to define it as a string. With that correction the code now works. I've applied this logic to my hangman code and I no longer recieve...
Here is the code I tried for the indexOf method:
public class Tests
{
public static void main(String[] args)
{
String str = "01234";
String substringOne = str.substring(0,...
If I replace the for loop with secretWord.indexOf(guess), I lose the use of int variable index for determining where guess should appear in displayWord. How do I print displayWord with the correct...
Thank you, that makes sense. I had them mislabeled in my head. So, you're asking me why I use this loop at all? I use it to loop through the length of secretWord until it matches the character at...
Which loop do you mean?
if(secretWord.charAt(guess) == guess.charAt(0)) or
for(int index = 0; index < secretWord.length(); index++) or
if(secretWord.indexOf(guess) >= 0)
If you are...
What do you mean when you say "just use the value returned by the indexOf method"?
I fixed the practice problem and it prints correctly now:
String str = "01234";
String updatedStr = "";...
(The word is: -----) What is encapsulated in the parentheses is from displayWord.
Here's what I have to replace "3" with X:
String str = "01234";
String updatedStr = "";
for(int index = 0;...
updatedDisplayWord holds substringOne (the number of dashes in displayWord from 0 to index) + the guessed letter + substringTwo (the number of dashes from index to the end of displayWord)
This is...
I'm not sure how I can get updatedDisplayWord to update every round of the game while also holding the value of the rounds before it, I need some help in figuring it out. When I don't add displayWord...
I was trying to think of some way to store the updated string every round, I'm not quite sure how to go about this. Also, I added displayWord += "-"; because when this line isn't added in the for...
The lines:
for (int index = 0; index < secretWord.length(); index++) //Loop over secretWord
{
displayWord += "-";
if (secretWord.indexOf(guess) == index) //If indices match
{...
Yes, I'm talking about substringTwo = displayWord.substring(index). The value of displayWord is ----, the value of index changes as it loops through the length of secretWord (starting at 0, and then...
Here are new debug print statements:
The secret word is: Java
The word is: ----
Enter the number of spaces allowed: 4
Enter the letter you want to guess: v
Your guess is in the word!
...
Here are some print statements for relevant variables:
VARIABLE OUTPUTS FOR DEBUGGING PURPOSES ONLY
Value of secretWord: algorithms
Value of displayWord: -----------
Value of index at end of...
I have used paper and pencil, but I'm still struggling with the logic behind it I suppose. In my new code, the problem is my substringTwo variable. It isn't printing out the correct number of dashes...
Thank you! That makes a lot of sense, I overlooked that. I changed to a substring method in the for loop over displayWord because I thought it would help more, and I think I've made a bit of...
This snippet of code...
for(int index = 0; index < secretWord.length(); index++)
{
displayWord = "-";
System.out.print(displayWord);
}
...prints out the correct number of dashes...
This is what I'm trying to figure out. I tried splitting it into substrings, like this:
System.out.print("Enter your guess: ");
String guess = input.next().substring(0, 1);
for(int index =...
displayWord is supposed to be the "hidden" version of the secret word that is generated randomly. It is displayed as a series of dashes that is equal in length to the secret word. I set up a for loop...