Variables and types

Print the number of full pairs and the remaining tickets as two lines. For 5 tickets, there are 2 pairs and 1 ticket left.

Examples

Example 1

Input
5
Expected output
2
1

Example 2

Input
8
Expected output
4
0

Starting point

public class Main {
    public static void main(String[] args) {
        int tickets = 5;
        // Print the full pairs and remaining tickets.
    }
}

Hints and solution

Hint 1

Use / for full pairs and % for the remainder.

Reveal worked answer

Divide two integers by computing tickets / 2. Use tickets % 2 to find whether one ticket is left over.

public class Main {
    public static void main(String[] args) {
        int tickets = 5;
        System.out.println(tickets / 2);
        System.out.println(tickets % 2);
    }
}
Back to the lesson