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"); } } }
3 Antworten
+ 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.
+ 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..
0
Thanks