• Post Reply Bookmark Topic Watch Topic
  • New Topic

Word Seach puzzle  RSS feed

 
James Dobson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with this code? It is supposed to take in an array along with a sum to find. then it searches that array to find consecutive vertical or horizontal numbers that sum up to the sum you are looking for.

Tester class.


Desired output:




My output:


 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

Welcome to CodeRanch!

Good to see that you are using code tags in your first post itself.

Either I didn't understand your question properly, or the code is working as expected.

In first test, I see that number which add upto 7 (7 is the input) are kept in the array, and rest are modified to 0.

In second test, no number add upto 22, and hence all numbers are modified to 0.

Can you please let us know what is exact expected behavior (maybe with examples) and what exactly is not working?
 
James Dobson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code I currently have only prints out zeros instead of leaving the consecutive numbers that add up to 7. I don't know why. Also, i don't know why my code prints out the array when running "arrayToStringTest();". Its only supposed to say passed or failed.

Also, I meant that is the desired output. Not my current output.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your arrayToStringTest method calls arrayToString(array1). arrayToString then prints the array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!