Challenge: Count the Lucky Sevens

Lab Java Beginner 10 points

A shop gives a prize to every ticket whose number ends in 7. Read n ticket numbers and print how many win. Look at each ticket once: that's O(n).

Input

Line 1: n. Line 2: n positive whole numbers.

Output

The number of winning tickets.

Example

Input

6
17 23 7 100 4507 70

Output

3
Sample input available Sample output available
Editor
Java

Hints

The last digit of a number is number % 10.

Add 1 to a counter for every ticket whose last digit is 7.

Solution explanation

We don't even need an array: each ticket is read, checked and forgotten. O(n) time, O(1) memory.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int winners = 0;
        for (int i = 0; i < n; i++) {
            int ticket = sc.nextInt();
            if (ticket % 10 == 7) winners++;
        }
        System.out.println(winners);
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD