Amazon interview question

reverse a string

Interview Answer

Anonymous

10 Feb 2013

public static void main(String []args) { String value; int length; int i=0; Scanner in= new Scanner(System.in); System.out.print("Enter the String to be reversed : "); value=in.nextLine(); length=value.length(); String revString=""; for(i=length-1; i!=-1; i--) revString+=value.charAt(i); System.out.print("Reversed String : "); System.out.print(revString); }