-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseWords3.java
More file actions
executable file
·33 lines (32 loc) · 958 Bytes
/
ReverseWords3.java
File metadata and controls
executable file
·33 lines (32 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Neel_Kapadia
*/
public class ReverseWords3 {
public String reverseWords(String s) {
StringBuilder sb=new StringBuilder();
String [] str;
str = s.trim().split("\\s+");
s = "";
for(int i = 0;i<str.length;i++){
sb = sb.append(str[i]);
sb = sb.reverse();
String x = sb.toString();
s = s.concat(x);
if(i!=str.length-1)
s = s.concat(" ");
sb.delete(0, sb.capacity());
}
return s;
}
public static void main(String[] args) {
ReverseWords3 rw = new ReverseWords3();
String x = rw.reverseWords("Hi I am Neel Kapadia");
System.out.println(x);
}
}