0

Explain what's wrong?

I solve tasks from the code simulator. I am just starting to learn Java and after the topics I have covered, I try to solve tasks in order to consolidate my knowledge. But there were difficulties with this. Help or advice me something please.

11th May 2022, 6:48 PM
CH2N
5 Answers
+ 2
//read the comments I added next : if(siblings != 0) { int amount = iceCream % siblings; if(siblings > 0 && amount % 2 == 0) { //what you mean amount%2==0 ? You just need to check amount==0 System.out.println("Give away"); //use small g, "give away" } else { System.out.println("Eat them yourself"); // again here, print as required and mentioned according to task description... "eat them yourself" } } else { System.out.println("Incorrect data. Please try again"); // this is no need.. And also no need to check siblings! =0 or siblings>0 , input is always a positive integer.. #hope it helps to correct mistakes..
11th May 2022, 7:11 PM
Jayakrishna 🇮🇳
+ 2
OMG, it was all solved in a line, as I didn't understand it right away... Now I'm ashamed of my question... By the way thanks for your advice, it helped me to see and understand my problem!👍
11th May 2022, 7:35 PM
CH2N
+ 1
What need to do. You have a box of popsicles and you want to give them all away to a group of brothers and sisters. If you have enough left in the box to give them each an even amount you should go for it! If not, they will fight over them, and you should eat them yourself later. Task Given the number of siblings that you are giving popsicles to, determine if you can give them each an even amount or if you shouldn't mention the popsicles at all. Input Format Two integer values, the first one represents the number of siblings, and the second one represents the number of popsicles that you have left in the box. Output Format A string that says 'give away' if you are giving them away, or 'eat them yourself' if you will be eating them yourself. Sample Input 3 9 Sample Output give away ----------
11th May 2022, 6:55 PM
CH2N
+ 1
/* given code by condition import java.util.Scanner; public class Popsicles { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int siblings = sc.nextInt(); int iceCream = sc.nextInt(); */ /* my code if(siblings != 0) { int amount = iceCream % siblings; if(siblings > 0 && amount % 2 == 0) { System.out.println("Give away"); } else { System.out.println("Eat them yourself"); } } else { System.out.println("Incorrect data. Please try again"); } } }
11th May 2022, 6:56 PM
CH2N
0
Share your try here?
11th May 2022, 6:51 PM
Jayakrishna 🇮🇳