• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Small problem with arrays in Hangman java game

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone...

I have coded this Hangman prog as a school project, however I am experiencing a small problem. The program prints a number of *s for every random word that is chosen. For instance, the word "oasis" would be *****. Yet, when printing the *s, it gives the last letter of the word a "null" value, in other words the array's last space is empty. For instance once again: oasis is now ****null...

And for some reason, if you type in the correct letter for the first letter of the word (in oasis "o"), it simply doesn't print it.

The problem would be in the test() void.

I am printing the code here. The text files (if you want to compile the program), can be found at http://www.geocities.com/kitaarmykruis/content.txt

Will anybody be willing to take a look?

I am also placing the driver program for anyone who wants to compile.




 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Yet, when printing the *s, it gives the last letter of the word a "null"
> value, in other words the array's last space is empty. For instance once
> again: oasis is now ****null...

create a demo program and strip everything unrelated to the problem

it may look like this



there is one notable difference in how you are filling the array,
and what you are printing from the array
 
author
Posts: 8995
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Klaas,

Well, we're all volunteers here so there's never a guarantee that a question will be answered in a specific amount of time. That said, I took a quick glance at your code and decided that I didn't want to wade through all of it looking a problem that's probably pretty isolated. I'd recommend that you send us a smaller bit of code that isolates the problem you're having, and you'll probably get a faster response. Also, you might find that when you isolate the bit of code that's causing you grief, you might just find the problem yourself!

hth,

Bert
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!