why if else is not working here public String theEnd(String str,boolean front) { if(front=true) return str.substring (0,1); else return str.substring (str.length()-1,str.length()); } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why if else is not working here public String theEnd(String str,boolean front) { if(front=true) return str.substring (0,1); else return str.substring (str.length()-1,str.length()); }

1st Oct 2016, 7:26 PM
Aamir Alam
Aamir Alam - avatar
2 Answers
+ 6
= is the assignment operator, you probably want to use == to check for equality instead.
1st Oct 2016, 7:35 PM
Zen
Zen - avatar
+ 1
You are setting the variable front equal to true.
1st Oct 2016, 8:05 PM
Mythos