Results 1 to 2 of 2

Thread: Java program

  1. #1
    MoralesWard is offline Senior Member
    Join Date
    Dec 2009
    Posts
    176
    Rep Power
    3

    Default Java program

    Java program to use enum in switch statement.

    I am last year BSc(IT) student. I want to write a Java program to use enum in switch statement. I tried different methods but none of them worked out. Can anybody tell me how to write this program?

  2. #2
    JenkinsReed is offline Senior Member
    Join Date
    Dec 2009
    Posts
    169
    Rep Power
    3

    Default

    The enum can be easily use in switch statement in java and use it like a different case to execute. Below example show you how to use enumeration or enum type in a switch statement.

    public class MainClass {
    enum Choice { Choice1, Choice2, Choice3 }
    public static void main(String[] args) {
    Choice ch = Choice.Choice1;

    switch(ch) {
    case Choice1:
    System.out.println("Choice1 selected");
    break;
    case Choice2:
    System.out.println("Choice2 selected");
    break;
    case Choice3:
    System.out.println("Choice3 selected");
    break;
    }
    }
    }
    Last edited by nitesh14; 02-06-2010 at 03:28 PM.

Similar Threads

  1. How to initiate Internet program with Java
    By WilsonMartin in forum Programming
    Replies: 0
    Last Post: 05-06-2010, 03:47 PM
  2. operating system java program
    By Williamsjones in forum Programming
    Replies: 1
    Last Post: 02-08-2010, 12:50 PM
  3. the ternary operator in java program
    By WilsonMartin in forum Programming
    Replies: 1
    Last Post: 01-28-2010, 06:07 PM
  4. statement in java program
    By PetersonClark in forum Programming
    Replies: 1
    Last Post: 01-27-2010, 02:50 PM
  5. Write program on palindrome in java
    By MoralesMyers in forum Programming
    Replies: 2
    Last Post: 01-14-2010, 06:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48