Last change
on this file since 2514d3d7 was
1725989,
checked in by Peter A. Buhr <pabuhr@…>, 5 months ago
|
add enumeration test programs for different programming languages
|
-
Property mode set to
100644
|
File size:
963 bytes
|
Line | |
---|
1 | import java.io.*; |
---|
2 | |
---|
3 | public class test1 { |
---|
4 | enum Weekday { |
---|
5 | Mon(7), Tue(6), Wed(5), Thu(3), Fri(3), Sat(3), Sun(1); // must appear first |
---|
6 | private long day; |
---|
7 | private Weekday( long d ) { day = d; } |
---|
8 | } |
---|
9 | |
---|
10 | public static void main( String[] args ) { |
---|
11 | Weekday cday = Weekday.Sat; |
---|
12 | System.out.println( cday.ordinal() + " " + cday + " " + cday.name() ); // label |
---|
13 | |
---|
14 | if ( cday == Weekday.Fri ) { // position |
---|
15 | System.out.println( "true" ); |
---|
16 | } |
---|
17 | // if ( cday < Weekday.Sat ) { // no releation operations |
---|
18 | // System.out.println( "true" ); |
---|
19 | // } |
---|
20 | switch ( cday ) { // position |
---|
21 | case Mon: case Tue: case Wed: case Thu: case Fri: |
---|
22 | System.out.println( "weekday" ); |
---|
23 | break; |
---|
24 | case Sat: case Sun: |
---|
25 | System.out.println( "weekend" ); |
---|
26 | break; |
---|
27 | } |
---|
28 | for ( Weekday icday : Weekday.values() ) { // position |
---|
29 | System.out.print( icday + " " + icday.ordinal() + " " + icday.day + " " + icday.name() + ", " ); // label |
---|
30 | } |
---|
31 | System.out.println(); |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | // java test1 |
---|
Note: See
TracBrowser
for help on using the repository browser.