Write a Java program to calculate the amount of candy each child at a party gets. You specify the number of children and the total amount of candy, then compute how many pieces each child gets, and how many are left over (for the parents to fight over!).

Respuesta :

tqiu

Answer:

import java.util.Scanner;

public class candy {

   public static void main(String[] args){

       Scanner sc = new Scanner(System.in);

       System.out.println("Type in number of children: ");

       //gets the number of children

       int numberOfChildren = Integer.parseInt(sc.nextLine());

       System.out.println("Type in number of candy: ");

       //gets number of candy

       int numberOfCandy = Integer.parseInt(sc.nextLine());

       //checks there will be any leftover candy

       int leftover = numberOfCandy%numberOfChildren;

       System.out.println("Each children will get "+(numberOfCandy-leftover)/numberOfChildren+" candies.");

       System.out.println("There will be "+leftover+" leftover candies.");

   }

}