+ 3
How to use greater than,less than operators in switch function ?
How to use greater than,less than operators in switch function ?
5 ответов
+ 4
Sorry, we cannot use such symbols in switch function.
Instead of using switch function, try using if - else statements.
+ 2
You cannot use if/else construct?
+ 2
A switch statement tests a variable for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
so you cannot
+ 1
It can be used in switch method.
Here's an example
int a = Integer.parseInt(t1.getText());
int b = 0;
switch (b =(x>= 18 && x<= 60)? 0:1)
{
case 0 :
t2.setText(" " + " You are eligible to vote");
break;
case 1 :
t2.setText(" " + " You are not eligible to vote");
break;
default :
t2.setText(" " + " Enter a valid input");
}
0
int y = 3;
switch (y)
{
case 1 :
System. out. println ( "Yes, it is one");
break;
case > 2 :
System. out. println ( "Yes, it is more than two");
break;
default :
System. out. println ( "Invalid number");