Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

enum in JDK 1.5.07

807599Jan 8 2007 — edited Jan 8 2007
Hi everyone,

I am new to Java 5, and I am try to recompile the code below in learning the enum, but I got some compiling error such as around the enum. It said that "Syntac error on token "enum" ....

If you have worked through this problem, could you please let me know what is wrong from my code, thanks for your help!

Dung.

--------------------------

package chapter3;

public class EnumTest {

public static void main(String[] argv) {

if ( argv.length < 1 ) {
System.out.println("Usage: java EnumTest [num char]");
System.exit(1);
}

else {
NUM_INFO ni = Enum.valueOf(
NUM_INFO.class, argv[0].toUpperCase());
System.out.println(
"Char : " + ni.getNumChar() + "\n" +
"Value: " + ni.getNumValue()
);
System.out.println("Name of the Num Info : " + ni.name());
}
}
}

enum NUM_INFO {
ONE ('1', 1.0/6.0),
TWO ('2', -2.0/6.0),
THREE ('3', 3.0/6.0),
FOUR ('4', -4.0/6.0),
FIVE ('5', 5.0/6.0),
SIX ('6', -6.0/6.0);

private final char numChar;
private final double numValue;

NUM_INFO(char numChar, double numValue) {

this.numChar = numChar;
this.numValue = numValue;
}
public char getNumChar() {

return this.numChar;
}
public double getNumValue() {

return this.numValue;
}
}

Comments

Rmanus-Oracle

Access to the support repository is not free. You need a valid support contract in order to have access to it.

This is one of the benefits of

Oracle Premier Support for Systems

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 5 2007
Added on Jan 8 2007
1 comment
205 views