ordinal java

Solutions on MaxInterview for ordinal java by the best coders in the world

showing results for - " ordinal java"
Elina
02 Jun 2020
1package com.tutorialspoint;
2
3import java.lang.*;
4 
5// enum showing Mobile prices
6enum Mobile {
7   Samsung(400), Nokia(250),Motorola(325);
8  
9   int price;
10   Mobile(int p) {
11      price = p;
12   }
13   int showPrice() {
14      return price;
15   } 
16}
17
18public class EnumDemo {
19
20   public static void main(String args[]) {
21
22      System.out.println("CellPhone List:");
23      for(Mobile m : Mobile.values()) {
24         System.out.println(m + " costs " + m.showPrice() + " dollars");
25      }
26
27      Mobile ret = Mobile.Samsung;
28      System.out.println("The ordinal is = " + ret.ordinal());
29      System.out.println("MobileName = " + ret.name());                      
30   }
31}