rahajengdwp

Untitled

Mar 6th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. //8.11 EnumTest.java
  2. //Testing enum type book
  3. import java.util.EnumSet;
  4.  
  5. public class EnumTest
  6. {
  7. public static void main (String[] args)
  8. {
  9. System.out.println("All books:\n");
  10.  
  11. //print all books in enum Book
  12. for(Book book: Book.values())
  13. System.out.printf("%-10s%-45s%s\n", book, book.getTitle(), book.getCopyrightYear());
  14.  
  15. System.out.println( "\nDisplay a range of enum constants:\n" );
  16.  
  17. //print first four books
  18. for(Book book: EnumSet.range(Book.JHTP, Book.CPPHTP))
  19. System.out.printf("%-10s%-45s%s\n", book, book.getTitle(), book.getCopyrightYear());
  20. } //end main
  21. } //end class EnumTest
Advertisement
Add Comment
Please, Sign In to add comment