HCL Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
package test.careercup;
public class ReverseWords {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "Hello world good morning";
String[] split = s.split(" ");
String[] revArray = new String [s.length()];
for(int i=split.length-1,j=0; i>=0; i--){
revArray[j]=split[i];
System.out.println(revArray[j]);
j++;
}
}
}
Use a stack. Push all the words in stack and then pop them.
- Anonymous April 16, 2013