Apple Interview Question

How do you reverse a string?

Interview Answers

Anonymous

Mar 23, 2020

Using inbuilt function reverse() or by using for loop. E.g: String str = "Reverse a string program"; String temp =""; System.out.println ("String before reversing" +str); for (int i =str.length()-1; i>=0;i--) { temp = temp+str.charAt(i) } System.out.println("String after reverse" +temp);

1

Anonymous

Apr 1, 2016

Point at the start of the string and the end and work till you hit the middle.

1