Apple Interview Question

read in a string and output it backwards

Interview Answers

Anonymous

Feb 14, 2013

public void (String input) { if (input == null || input.length == 0) return; for (int i = input.length-1; i >= 0; i--) { System.out.print(input.charAt(i)); } System.out.println(); }

2

Anonymous

Feb 3, 2015

public static void main(String [] args) { String a = "qwerty", rev = ""; //Scanner sc = new Scanner(System.in); //System.out.println("Enter the string : "); //String a = sc.nextLine(); for(int i = a.length()-1; i >= 0; i --) { rev = rev + a.charAt(i); } System.out.println(rev); }

Anonymous

May 27, 2019

myString[::-1]

Anonymous

Jun 4, 2011

i said push each letter into a stack then pop and output repeatedly until there were no more letters

Anonymous

Dec 14, 2011

void printrev(const char* str) { if(*str=='\0') return; printrev(str + 1); cout<<*str; }