Apple

www.apple.com
Employer Engaged

Interview Question

Software QA Engineer Interview(Student Candidate)

read in a string and output it backwards

Answer

Interview Answer

4 Answers

0

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

Interview Candidate on Jun 4, 2011
0

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

Anonymous on Dec 13, 2011
0

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();
}

BCM on Feb 14, 2013
0

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);
}

Arun on Feb 3, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.