//It is a corrent choice to use startsWith.
//Be careful in using empty string
String hello = "yes";
if (hello.startsWith("yes"))
System.out.println("Morning");
if (hello.startsWith(""))
System.out.println("Good Evening");
// you can use charAt for one character but more coding is needed
Could you give me an example of using charAt? I understand that it may be more code, but wouldn't it cover more varieties of input like just Y. Would their be issues with upper case and lower case?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.