Question: So I have some java code that needs to throw out every single element containing the number 5 and return the count. So far I have:

```
public static int noFive(int start, int end) {

         ArrayList<Integer> arr = new ArrayList<Integer>();
         int result = end - start + 1;

        for (int i = start; i <= end; i++) {
            arr.add(i);
        }

        for (Integer i : arr) {
            if (i % 5 == 0) { //my problem is here i try to do this but i know this does not eliminate numbers such as 51, 52, 53 etc.
                result--;
            } else {
                continue;
            }
        }

        System.out.println(result);
        return result;
    }

```

I searched up the ArrayList doc and it says that the contains method only throws out the elements containing 5 and only 5. But I want a program that throws out stuff like 51, 52, 53, stuff that are not divisible by 5.

Answer: 
Try this. I just modified the @stackguy code. ideone link <https://ideone.com/aL7EFt>

```
import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
    public static void main (String[] args) throws java.lang.Exception{
        noFive(1,60);

    }

    public static int noFive(int start, int end) {

         ArrayList<Integer> arr = new ArrayList<Integer>();
         int result = end - start + 1;

        for (int i = start; i <= end; i++) {
            arr.add(i);
        }

        for (Integer i : arr) {
             if (!(i % 5 == 0) && hasFive(i)) {  //it will remove all numbers as 51, 52, 53 etc.
                result--;
                System.out.print(i+",");
            }
        }

        System.out.println(result);
        return result;
    }

        private static boolean hasFive(int num) {
        int rem;
        while (num > 0) {
            rem = num % 10;
            if (rem == 5)
                return true;
            num = num / 10;
        }
        return false;
    }
}

```
Did you try something like this:

```
public static void main(String[] args) {
        noFiveCount(1, 9); //prints 8
        noFiveCount(1, 49); //prints 44
        noFiveCount(1, 59); //prints 44
        noFiveCount(1, 60); //prints 45
    }
    private static int noFiveCount(int start, int end){
        int result = end - start + 1;

        List<Integer> range = IntStream.rangeClosed(start, end)
                .boxed().collect(Collectors.toList());

        for (Integer i : range) {
            if (hasFive(i)) { 
                result--;
            } else {
                continue;
            }
        }

        System.out.println(result);
        return result;
    }
    private static boolean hasFive(int num) {
        int rem;
        while (num > 0) {
            rem = num % 10;
            if (rem == 5)
                return true;
            num = num / 10;
        }
        return false;
    }

```