Extra-Terrestrials task problem | Sololearn: Learn to code for FREE!


Extra-Terrestrials task problem

I have the same output as the expected output but I can't complete the test. https://code.sololearn.com/c2eNdpku85hR/?ref=app

12/20/2019 9:47:07 AM

Илья Карпенко UA

5 Answers

New Answer


The problem is you starting to add characters beginning at size(), while the last character of the string is located at size() - 1, since strings are null-indexed, just like arrays.


Here you go. Done in Java. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String word = input.nextLine(); for(int x=word.length()-1;x>=0;x--){ System.out.println(word.charAt(x)); } } }


It's strange. The output was ok.


Sure, the output might seem okay, but they are likely comparing their solution to yours, which means the strings are being compared, and since your string would be longer by one character, even if not visible in the output, the comparison would fail, since they are compared first by length and then lexographically.


trying to my code: https://www.sololearn.com/coach/51?ref=app