Challenge: Share the Sweets

Lab Java Beginner 10 points

Read the number of sweets and the number of friends. Print how many sweets each friend gets and how many are left over.

Input

Two whole numbers: sweets, then friends.

Output

Each friend gets: <n>
Left over: <n>

Example

Input

17
5

Output

Each friend gets: 3
Left over: 2
Sample input available Sample output available
Editor
Java

Hints

int / int throws away the decimal part – exactly what we want here.

% gives the remainder.

Solution explanation

sweets / friends is integer division and sweets % friends is what's left over.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sweets = sc.nextInt();
        int friends = sc.nextInt();
        System.out.println("Each friend gets: " + (sweets / friends));
        System.out.println("Left over: " + (sweets % friends));
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD