Quantcast
Channel: Solved » switch-statement
Viewing full articles (5 articles)
Browse article index

Multiple Cases in Switch Java

$
0
0

Just trying to figure out how to use many multiple cases for a Java switch statement. Here’s an example of what I’m trying to do:

switch (variable)
{
    case 5..100:
        doSomething();
    break;
}

versus having to do:

switch (variable)
{
    case 5:
    case 6:
    etc.
    case 100:
        doSomething();
    break;
}

Any ideas if this possible, or what a good alternative is?

Solution

Sadly, it’s not possible in Java. You’ll have to resort to using if-else statements.

The post Multiple Cases in Switch Java appeared first on Solved.


Viewing full articles (5 articles)
Browse article index

Latest Images

Trending Articles



Latest Images