Here is my code for printing string characters turned upside down in Java without using any API. But it does not work properly. Can someone help me fix this?
public static void main(String args[]) { String input = "I am test"; String result = ""; for (int i = input.length() - 1; i > 0; i--) { Character c = input.charAt(i); if (c != ' ') { result = c + result; } else { System.out.println(result + " "); } } }
It gives the output "test amtest", and the output should be "test am I".
Please help me get the exact result without using predefined methods or APIs.
java string reverse
khanam
source share