How to use greater than,less than operators in switch function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to use greater than,less than operators in switch function ?

How to use greater than,less than operators in switch function ?

23rd May 2018, 10:16 AM
Captain RakZ
Captain RakZ - avatar
5 Answers
+ 4
Sorry, we cannot use such symbols in switch function. Instead of using switch function, try using if - else statements.
24th May 2018, 10:26 AM
Rahul Hemdev
Rahul Hemdev - avatar
+ 2
You cannot use if/else construct?
23rd May 2018, 11:29 AM
KrOW
KrOW - avatar
+ 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
6th Jun 2018, 8:17 PM
Saifur Rahman
+ 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"); }
12th Aug 2018, 8:00 AM
Tanmayee Gaikwad
Tanmayee Gaikwad - avatar
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");
14th Aug 2018, 11:57 AM
Tanmayee Gaikwad
Tanmayee Gaikwad - avatar