November 16

The code snippet below is supposed to read in from Holidays.txt and print out the first four holidays in the file.  What is wrong with the snippet?  (Hint:  look at the scanner and at the loop condition.)

import java.util.Scanner;
public class Holiday {

    public static void main(String [] args) {
        Scanner scan = new Scanner("Holidays.txt");
        int num = 0;
        while (scan.hasNext && num > 4) {
            System.out.println(scan.nextLine());
            num ++;
        }
    }
}

Assume Holidays.txt has the following data:

New Year  Jan 1
Valentine's Day Feb 14
St. Patrick's Day Mar 16
April Fools!  April 1
Memorial Day  May 28
4th of July   July 4
Labor Day     Sept 1
Halloween     Oct 31
Veteran's Day  Nov 11
Christmas     Dec 25