eBay Interview Question: Write a code in java to read ... | Glassdoor

Find your next job here

Interview Question

QA Engineer Interview

Write a code in java to read a file and then reverse its

  contents. Like if its written " My interview was bad" It should reverse in a way "bad was interview my" and not "dab saw weivretni ym"

Interview Answer

1 Answer


public static String reverseAsIs(String original){
            String[] strArray = original.split(" ");
            String[] reverse = new String[strArray.length];
            int len = strArray.length-1;
            for(int i=len; i>=0;i--){
            StringBuilder sb = new StringBuilder();
            for (String r : reverse)
                sb.append(" ");

            return sb.toString();

HK on May 21, 2017

Add Answers or Comments

To comment on this, Sign In or Sign Up.