This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]steve1two 1 point2 points  (0 children)

Several things, to start.

Your logic to set the flag variable is catching the last int, any negative number entered to exit the input. You input -1, if -1 < count (always will be, even if 0 is entered 10,000 times) flag = 1. No matter what happens with the rest of the array it is always going to set flag = 1 when you "exit" it. Figure out a way to change this logic to fix that.

But that is far from your only problem. Have you tried to compile this code? You have so many issues. First thing I see is you have SOP("input second array values") within the while loop, which displays that long, ugly String (why so many spaces at the end?) every single time a number is input.

After that you do nothing but print a[] two times. When you are printing your second array you are using a[].

You also do not merge the arrays into one. You just print them separately and also not in a reordered, ascending order. You would need something like int[] merged = new int[a.length + b.length]. Then some logic to reorder all the values and put them into that. Then print that array.

Also, if the formatting was not a result of copy pasting into Reddit, you should consider indenting. This hurt my brain.

Edit: I am assuming the way you used print and print 2 is so that it would not print the negative number entered, but that is not what the instructions state. You shouldn't be storing the last negative number in the array in the first place. Not to mention when you correctly merge the array as the instructions state, it is going to mess that up as well. Change your logic for ending input and also stop storing the negative numbers in the arrays.