I am not understanding why my solution isn't passing the 'If the entered number is negative, increase it by one and display the result.' test. When i input a negative number and run my code it outputs the correct answer e.g -10 outputs -9 but i can't pass the tests? Any hints for this would be appreciated.
-10 input is outputting -9 but won't pass the test?
Resolved
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
TempanyJ Frontend Developer
16 May, 16:17
Thank you Guadalupe and Lisa, I looked over this again today and it finally clicked! I actually needed two else if statements so that it doesn't output twice, I was missing the obvious!
0
TempanyJ Frontend Developer
13 May, 08:26
/* Comment has been deleted */
0
Lisa L
13 May, 09:39useful
?? Please consider what Lupe has written. Maybe test your current code with -1 to see the problem in action.
+2
Guadalupe Gagnon
12 May, 15:04solution
if number is less than 0 this code adds 1 to the number. It then checks if the number is greater then zero, which it wont be, else checks if the number is equal to 0, which it may well be at this point if the user had entered -1. In that case it will output 0 two times(line 30 and line 36), which is not what the conditions describe the code should do. This logical error needs to be fixed before the code will pass.
+3
Lisa L
12 May, 16:46
Man, once again not seeing the obvious, hahaha. It's an if not an else if. Good that you're back again.
+1
Guadalupe Gagnon
12 May, 16:55
=P
I know what you mean
I have, on more than one occasion, deleted a comment I had previously made replying to a question after you add a comment that is actually correct.
+1
Lisa L
12 May, 14:15
No clue why it does not validate but I'd start with line 36 and output number or at least int 0 instead of a String. Maybe validation wants to see a call to the println(int) method in any case?
0
Coboliste
11 May, 15:21
Hi there,
Why don't you use simply :
since you are sure that, the input will be a number ? 0
TempanyJ Frontend Developer
12 May, 14:08
I don't think you've looked at the question im referring to.
0
Coboliste
12 May, 16:00
I think the problem is in the line 35, if you remove the 'else' word, the code has to work correctly.
0