+ 1

Popsicles Challange Java

Hello everyone! I wrote a code to solve the challange but the third test case always fails. I tried I think every cases, but I cannot find the problem. Here's the code: https://code.sololearn.com/cmWCekmcKp9j The inputs I have tried: Sibling / Popsicles 2 2 1 2 2 1 1 1 0 1 1 0 0 2 2 0 0 0 What did I miss? Thank you all! Love, Llama

31st Aug 2022, 5:51 AM
Zoltán Szabó
4 Answers
+ 2
Found it! I misunderstood the task. To all who are struggling, read the task again and pay attention to the sample inputs and outputs! You'll get it.
31st Aug 2022, 6:55 AM
Zoltán Szabó
+ 3
Be patient “Any software engineer will likely give a new coder the same advice: be patient. Coding, while great, is one of the most frustrating things to learn. You’ll spend three hours staring at your code, wondering why it’s not working, only to be missing a semicolon somewhere. But when you finally get it working, it’s worth it.”– Jake Byman, Senior Software Engineer
31st Aug 2022, 6:59 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
/* Hi! I reduced the code of your program by removing all unnecessary ones. but it is still not perfect, and reproduces the wrong value in Test 3. do not add anything extra to the code from yourself, except for what is required in the task. most likely you have a logic error. think more carefully */ try { if(siblings % 2 == 0 && popsicles % 2 == 0) { System.out.println("give away"); } else { System.out.println("eat them yourself"); } } catch (Exception e) { System.out.println(e); } } }
31st Aug 2022, 6:17 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thank you! I added the changes and it works, but as you said, the third is still failing. The way I wrote my code is because I wanted to test it for every cases and see a different output. I use IntelliJ, since Code Coaches aren't a thing on PC. The code you gave me outputs the give away string when popsicles and siblings are 0 right? I don't like the feeling to give nothing to no one. 😂 That is an other reason why I code like this. And I like to talk. 😂
31st Aug 2022, 6:44 AM
Zoltán Szabó