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
Илья Карпенко UA5 Answers
New AnswerThe 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)); } } }
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.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message