-3

I'm pretty sure that my logic is right but it doesn't print anything. Can anyone please take a look at my code. It supposes to print the string backward. But it doesn't print anything. It doesn't give me an error either. Thanks

String x = input.nextLine(); for(int i = x.length()-1; i<=0;i--) { System.out.println(x.charAt(i)); } 
2

1 Answer 1

1

<= vs >=. For backward you loop should check >=

 for(int i = x.length()-1; i<=0;i--) { System.out.println(x.charAt(i)); } 

Should be

 for(int i = x.length()-1; i>=0;i--) { System.out.println(x.charAt(i)); } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, so it was a logical error Thanks again

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.