Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Testing enum type Book.
  2. import java.util.EnumSet;
  3.  
  4. public class EnumTest
  5. {
  6. public static void main( String[] args )
  7. {
  8. System.out.println( "All books:\n" );
  9. // print all books in enum Book
  10. for ( Book book : Book.values() )
  11. System.out.printf( "%-10s%-45s%s\n", book,
  12. book.getTitle(), book.getCopyrightYear() );
  13.  
  14. System.out.println( "\nDisplay a range of enum constants:\n" );
  15.  
  16. // print first four books
  17. for ( Book book : EnumSet.range( Book.JHTP, Book.CPPHTP ) )
  18. System.out.printf( "%-10s%-45s%s\n", book,
  19. book.getTitle(), book.getCopyrightYear() );
  20. } // end main
  21. } // end class EnumTest