Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package forExam;
- public class Exam {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println(reverseString(" hello world in java"));
- }
- public static String reverseString(String str)
- {
- String res = "";
- String tempstr = "";
- for(int i = 0; i < str.length() ; i++)
- {
- if(str.charAt(i) == ' ')
- {
- if(tempstr != ""){
- res = tempstr + " "+ res;
- tempstr = "";
- }
- }
- else
- {
- tempstr = tempstr + str.charAt(i);
- if(i == str.length()-1)
- {
- res = tempstr + " "+ res;
- }
- }
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement