Java Sandwich


Collapse Content

Time for some more challenging problems!

A "Java Sandwich" is a String that contains the word "Java" near the middle of it. "Near" means that the number of characters to the right and left differ by at most 2 characters.

For example, "Watch the Java master code" is a Java sandwich, since it contains 10 characters to the left and 12 characters to the right.

Challenge

Create a program that prints true if a sentence is a "Java Sandwich" and false otherwise.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Comments

  • Uhm a space is not a character right?

  • It shouldn't make a difference in this challenge, but a space is a character just like any other.

  • Thx
    it does matter since i have to count them in, right.

  • Yes that's correct, you need to count the spaces. (I thought there were the same number of spaces on each side, but I see that's not the case.)

  • I solved it, but i stil get wrong output one 1 item. The fault is not my code this thime! check it.

    for 12Java12345 i get true and i thould be false. When i run it in eclips it gives false ( so its not my code).
    what is going wrong?

Contact Us
Sign in or email us at [email protected]