File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange system.out

 
Brian Pianczk
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way I know how to have this looked at is to post the whole code and the returned results.
I have a feeling it has something with reading the array from right to left and then trying to display it left to right with another array.



My returned statement is: A plus B = (wont display what it dsiplays on the console, which are 8 boxes)

 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this code instead, and i'll let you know what the errors where....



ok first, your for loop in the plus method was like this...

for( int i = a.length -1; i < 0; i ++)...

obvious and easy to make mistake, but if i = the length of your array -1
then i will always be > 0 so the conditional 'i < 0' in the for loop made the
loop never execute, and also the 'i++' needs to be 'i--' going from right to left...

next was that some of your '0' and 'o' were getting mixed up, and also you had something
like: 'result[i] = 1' instead of 'result[i] = '1'', it is a character array, not integer.

and finally in the main method, you were calling something like....

System.out.println( String.valueOf(test2.plus(a,b)));

If you look at the return type of plus, it is a array, so you would need to set that return
variable to an instance of char[] and then loop through and print it out.

you can comment out the "got here" and the other two println comments, thats just how
i debugged it.

Hope this helps ya out,

Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put in : 00000001 and 00000010 and got 00000011
1 + 2 = 3;

Thats the only test i ran, you might want to test larger number to
see if they come out right.

Justin
 
Brian Pianczk
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justin Fox wrote:I put in : 00000001 and 00000010 and got 00000011
1 + 2 = 3;

Thats the only test i ran, you might want to test larger number to
see if they come out right.

Justin


Yeah, Justin I looked again , and in my haste didnt notice I cut and pasted my final code together, from my tests wrong, I am sorry for this.

I appreciate your going through and looking at it. I didnt notice the looping was wrong.

Thanks
 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem,

I enjoy helping when I can lol.

Justin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic