+ 1

if (name.substring(0,1) == name1.charAt(0) )

name is a user input and name1 is a predefined String am comparing if the first letter is equals to user input then printing some text....But am getting error if (name.substring(0,1) == name1.charAt(0) ) on this...... regards... revuri.

19th Dec 2017, 6:51 AM
Revuri kiran
Revuri kiran - avatar
2 Answers
+ 9
name.substring will return a string while name1.charAt will return a char, you cannot use the "==" operator on different data types
19th Dec 2017, 7:33 AM
David Akhihiero
David Akhihiero - avatar
+ 2
you are comparing a string and a char. Doesnt work that way.
19th Dec 2017, 6:55 AM
Jeremy
Jeremy - avatar