• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot see what I am missing converting string to array  RSS feed

 
Ben Saberton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys

So this will be undoubtedly a stupid question but here it goes anyway :P

I am obviously new to programming and Java so I set myself the goal of creating a very simple auto type style of program so it gets the users input and relays it out again but potentially to another window (I am currently testing to notepad). The reason I am trying to make it is because i thought it could be quite simple and I can build on it as a project to make it better.

The issue I am having is that it outputs the first character to the window I am selected (again testing into notepad) but then stops and doesn't output anything else. I tried to figure out what was going on by putting a System.out.println(arr[6]); after the delay method but it just output a line so almost like what I was putting into the array was only storing the first character of the string? I cannot figure out why that would be...

I hope I am making sense if not please let me know and I can try to explain better, if you are able to help would be greatly appreciated!


 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a 'return' in every case statement so as soon as the key is released the method exits and hence the program exits. Rather than 'return' use 'break'
 
Ben Saberton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/facepalm

Thank you very much haha!
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry we've all been there.

BTW Repeating code is generally a sign of a poor design and you have a lot of repeated code there, before you add support for numbers, capital letters, symbols etc. Can I suggest you think of how you might reduce your line count.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!