Karen
Karen

Reputation: 29

How to convert switch statement to if else statement for java

a and b are both int variables.

switch (a) {
    case 0: b ++; break;
    case 1:
    case -2: b *= 2; break;
    case 4: b = 10 * a;
    default: b *= a;
}

How would I write this as a if else statement in as simple of a manner as possible? Coding in Java.

Upvotes: 0

Views: 4522

Answers (1)

Skathix
Skathix

Reputation: 278

In c++

    if(a == 0)
      {
       ...
      }
    else if(a == 1)
      {
       ....
      }
    ...
    /* continues to default case, default follows */
     else
      {
       //default parameters
      }

Upvotes: 1

Related Questions