Reputation: 39
class dd
{
public static void main(String args[])
{
short dd = 5;
switch (dd)
{
case !1:
case !2:
case !3:
case !4:
System.out.println("Pf");
}
}
}
So I have this small part of code, I know it is wrong, all I want to know is how I can make the if ( SomeVariable ! = SomeNumber )
using the swtich-case
command. Thank you in advance.
Upvotes: 0
Views: 56
Reputation: 124646
A case cannot be about not-something. But you can use the default:
case instead:
short dd = 5;
switch (dd)
{
case 1:
case 2:
case 3:
case 4:
break;
default:
// matched none of the above cases
System.out.println("Pf");
}
Upvotes: 3