Reading integers from a text file containing integers and strings : So here is my code and the only options I have in the chapter we are on are the while (!scan.hasNextInt()).  This is my code and it works until I try to read a file with strings. The file looks like this:

1
2
John
3
4
Black
5
Jason
7
8

I do not understand how to use this method.

My code:

    import java.util.Scanner;
    import java.io.File;
    import java.io.IOException;


    public class Main {

        public static void main(String[] args) throws IOException {
            int number;
            int temp;
            int i;
            boolean isPrime = true;
            double count = 0.0;
            double total = 0.0;


            File inputFile = new File("Values.txt");
            Scanner file = new Scanner(inputFile);

            while (file.hasNext())
                 {
                if (!file.hasNextInt()) {
                    String s = file.nextLine();
                 }
                else {
                     number = file.nextInt();
                }

                for (i = 2; i <= (number / 2); i++)
                {
                    temp = number % i;
                    if (temp == 0)
                    {
                    isPrime = false;
                    break;
                    }
                 }
                if (isPrime) {
                     //System.out.println(number);
                     total = total + number;
                     count = count + 1.0;
                 }

             isPrime = true;

             }
             //System.out.println(total);
             //System.out.println(count);
             System.out.println(total / count);
             System.out.println("File is Empty");
             file.close();
         }

     }
