Results 1 to 4 of 4
  1. #1
    funjoke is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default convert switch to if -else in java

    int age;
    switch(age=19){
    case1:case2:case3:case4:case5:
    case6:case7:case8:case9:case10:
    System.out.println("Child");
    break;
    case18:case19:
    System.out.print("Legally adult but also a");
    case11:case12:case13:case14:
    case15:case16:case17:
    System.out.println("Teenager");
    break;
    default:
    System.out.println("Adult");
    break;
    }


    do you all know how to convert to if-else ?

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: convert switch to if -else in java

    Java Code:
    if (age==18 || age==19) {
        // Legally adult but also a
    }
    
    if (age <11) {
        // Child
    } else if (age >=11 && age <=19) {
        // Teenager
    } else {
        // Adult
    }
    Whats hard about that? :P

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: convert switch to if -else in java

    Moved from 'Forum Guides'

    Quote Originally Posted by ozzyman View Post
    Whats hard about that? :P
    The question was asked nearly two years ago and probably didn't get any responses due to being posted in the wrong section of the forum.

    Was it really necessary to bump it? Did you really think that a member who hasn't posted here since that question would come back to answer your question?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: convert switch to if -else in java

    My bad, a) didn't realise the date (due to it being in a dead subforum) and b) mislead by the name 'funjoke' to think it was a fun java puzzle/joke.

Similar Threads

  1. how to convert * into : using java
    By Ricks in forum New To Java
    Replies: 2
    Last Post: 02-02-2010, 04:57 PM
  2. Convert .java to .exe
    By susan in forum New To Java
    Replies: 6
    Last Post: 02-11-2009, 06:47 AM
  3. Replies: 4
    Last Post: 01-01-2009, 04:21 PM
  4. Convert java to .exe
    By heartysnowy in forum New To Java
    Replies: 13
    Last Post: 11-21-2008, 08:16 AM
  5. Problem with a switch statement in Java
    By baltimore in forum New To Java
    Replies: 2
    Last Post: 08-02-2007, 04:43 AM

Posting Permissions

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