Finding how many consecutive numbers there are
<p>I need to find how many consecutive numbers come up in my random number generator, I have the program working except for the consecutive numbers part. Here is what ive got. I have tried many things but for some reason I just cant figure it out, please help! There is 1000 numbers and 500 random numbers come out, then I found the smallest and the largest values and then the average. Now I need to find how many consecutive numbers come out f.e. 9, 10, 11 or 55, 56, 57... 
I am also getting this error...
--Exception in thread "main" java.util.NoSuchElementException</p>

<pre><code>    int num, largest, smallest, sum = 0, count = 0;
    int programnumber = 6;
    header (prw, programnumber);
    double average = 0;

    Random gen = new Random();
    FileWriter fw = new FileWriter("randomdata.txt");
    for (int i1 = 0; i1 &lt; 500; i1++){
        num = gen.nextInt(1000);
        fw.write(num + "\n");
        count++;

    }
    fw.close();

    File numfile = new File("randomdata.txt");
    Scanner infile = new Scanner(numfile);
    largest = infile.nextInt();
    smallest = infile.nextInt();
    largest = 0;
    smallest = 999;
    while (infile.hasNext()){
        num = infile.nextInt();
        System.out.println(num);
        if (num &gt; largest){
            largest = num;
        }
        if (num &lt; smallest){
            smallest = num;
        }
        sum = sum + num;
        count++;
        }
    average = (double) sum / count;
    System.out.println("The largest is: " + largest);
    prw.println("The largest is: " + largest);
    System.out.println("The smallest is: " + smallest);
    prw.println("The smallest is: " + smallest);
    System.out.println("The average is: " + average);
    prw.println("The average is: " + average);

            // here is the part where I am stuck
    int prev, consec=0;
    prev= infile.nextInt();
    num= infile.nextInt();
    while (num &gt;= 0) { 
        if (num &gt;= prev){  
            consec++; 
            prev = num; 
            num = infile.nextInt();
        }

    }
    System.out.println(consec);








    prw.close();
}
</code></pre>
