Is there a solution to avoid those ORs
char c;
c='a';
if (c=='a') || (c=='z') || (c=='r') {System.out.println(c);}
I used to do it in pascal like if c in ['a','z','r'] then
char c;
c='a';
if (c=='a') || (c=='z') || (c=='r') {System.out.println(c);}
I used to do it in pascal like if c in ['a','z','r'] then
|
|
|
switch(c)
{
case a:
System.out.println(c);
break;
case z:
System.out.println(c);
break;
case r:
System.out.println(c);
break;
}
char c = 'z';
Character[] chars = new Character[]{'a','z','r'};
HashSet<Character> set = new HashSet<Character>(Arrays.asList(chars));
if(set.contains(c)){
System.out.println("Set contains: "+c);
} else System.out.println("Set doesn't contain: "+c);
switch (c)
{
case a:
case z:
case r: System.out.print("\nc");
}
0 members, 1 guests, 0 anonymous users