POST TITLE
POST TITLE
Problem link :- click here
Code
// ENUM CONSTRUCTOR
/*
Write a program to display the values of currency where in the currency will be PENNY(5),
DIME(10), NICKLE(15), QUARTER(25).
*/
public class Problem__5
{
enum Currency
{
PENNY(5), DIME(10), NICKLE(15), QUARTER(25);
int value;
Currency(int a)
{
this.value = a;
}
int getValue()
{
return this.value;
}
}
public static void main(String[] args)
{
Currency c[] = new Currency[4];
c[0] = Currency.PENNY;
c[1] = Currency.DIME;
c[2] = Currency.NICKLE;
c[3] = Currency.QUARTER;
for(Currency x:c)
{
System.out.println("The value of " + x + " = " + x.getValue());
}
}
}
Comments
Post a Comment