+ 3

I can't find out what did I do wrong

What I'm trying to do is asking user for a word and checking if the word starts with "a" or not. and I'm using if statement to check that. https://code.sololearn.com/c5a2Hs0YDpQ3/?ref=app

7th Feb 2018, 12:37 AM
[No Name]
[No Name] - avatar
5 Answers
+ 3
Nops ^_^
8th Feb 2018, 3:18 AM
Lucas Sousa
Lucas Sousa - avatar
+ 2
Some observations: 1) Fix "word" variable type to String (instead "string"); 2) Hint: you're trying check if word starts with checking if ENTIRE user input is equals to "a". This will only work if user type "a". If him type "apple" your code will return a wrong result; 3) Hint2: When you to try compare String (or objects as well), please, DO NOT USE == operator! Instead use "equals()" method. Example: System.out.println("apple".equals("car"));//shows "false"
7th Feb 2018, 12:49 AM
Lucas Sousa
Lucas Sousa - avatar
+ 1
I think you will need to use arrays to check if the first letter is "a" there are a few errors: your first System.out is not capitalized so that "class", I guess, is not called. your if condition could work with this since its "fixed" ("%s starts with a"); else condition should be something like: ("%s does not start with " + word); first problem I think was the concatenation then the use of "a" as a variable. It should be inside the string/quotation marks or use the string variable "word" instead. I dont really now Java anyways im starting to learn C# but no ones seems to be here to help lol
7th Feb 2018, 12:52 AM
kideoh0jima
+ 1
I want to thank everyone for helping, expressly ACE for posting the correct code. It helped me alot to understand what I did wrong.
8th Feb 2018, 3:15 AM
[No Name]
[No Name] - avatar