Test case is hidden, can someone tell what i did wrong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Test case is hidden, can someone tell what i did wrong

public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int siblings = input.nextInt(); int popsicles = input.nextInt(); //your code goes here double g,a,b,s,p; p= popsicles ; s= siblings ; g=(p/s)%10; a=p/s; b=Math.round((p/s)%10); if(b==0 || b==a){ System.out.println("give away"); }else{ System.out.println("eat them yourself"); } } }

25th Jul 2020, 1:20 PM
Aksayan Punniarajah
Aksayan Punniarajah - avatar
3 Answers
+ 3
This is much too complex, the correct solution is much much easier... Your various division and rounding steps do not lead to the information, if the popsicles are dividable by your siblings without any modulo. g contains the modulo, a the double value of the division. b is the rounded value of the modulo (and I think this is what finally leads to failure). But nothing just checks, IF there is any modulo and nothing else.
25th Jul 2020, 1:31 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Yes. There is no need of that much calculations. First, Pipesiples%siblings, Not (p/s) %10 And this step is enough for problem. Rethink about it. Else post your logic to get clarity, If you need. According to the your logic b==a always true..
25th Jul 2020, 1:38 PM
Jayakrishna 🇮🇳
0
Thanks
25th Jul 2020, 3:10 PM
Aksayan Punniarajah
Aksayan Punniarajah - avatar