View difference between Paste ID: jXZf6Unm and TVd5tiKx
SHOW: | | - or go back to the newest paste.
1
// Fig. 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,
14
        book.getTitle(), book.getCopyrightYear() );
15
 
16
        System.out.println( "\nDisplay a range of enum constants:\n" );
17
 
18
        // print first four books
19
        for ( Book book : EnumSet.range( Book.JHTP, Book.CPPHTP ) )
20
            System.out.printf( "%-10s%-45s%s\n", book,
21
            book.getTitle(), book.getCopyrightYear() );
22
        } // end main
23
 } // end class EnumTest