Advertisement
arafaee

EnumTest.java

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