GoodMorning.java



import java.util.Calendar;

public class GoodMorning {

    public static void main( String[] args ) {

        Calendar cal = Calendar.getInstance();
        int hour = cal.get( Calendar.HOUR_OF_DAY );

        if( hour > 5 && hour < 12 )
            System.out.println( "Good morning!" );
        else if( hour < 17 )
            System.out.println( "Good afternoon!" );
        else if( hour < 19 )
            System.out.println( "Good evening!" );
        else
            System.out.println( "Good night!" );
    }
}