Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi @ll
I am studying on Academy) with an online ide and it keeps on saying my answer is incorrect(on the websites intern ide). can not figure out what else to do.

The question:
Write a program that checks if a given string starts with the prefix "J" ignoring the case.
The program should output true or false.

My answer:

class Main {
        public static void main(String[] args) {
           String java = "Java";
           System.out.println(java.toLowerCase().charAt(0) == 'j'); //for the true return

thanks in advance

What I have tried:

startsWith, return, Scanner for own input, substring and contains(even tho it ignores the question for the prefix).
Updated 23-Sep-21 22:00pm
Richard MacCutchan 24-Sep-21 3:07am    
I just tried your code and it works fine, the output is:
java atest
Banguwonderful 24-Sep-21 3:30am    
I know, in my own ide it works just fine. but the online ide is the issue, it keeps on saying that i am wrong.

1 solution

You are wrong because you are using a fixed string, not the string they supply. A test suite won't expect you to return "true" every time: it will supply test cases that are expected to fail: "Hello" for example, an empty string as well.

Go back to where you got the instructions from, and read them again carefully - they should explain where to get the test string from (app parameters, or perhaps for example).
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900