JAVA
java
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
import java.util.*;
public class Program{
public static void main(String[] args){
String s = "go over there";
int start = 0;
char ch;
s = s + " ";//add space at the end
// using s.substring(start,i+1) includes the extra space between the words.
for(int i = 0;i<s.length();i++){
ch = s.charAt(i);
if(Character.isWhitespace(ch)){
System.out.println(
"--"+s.substring(start,i+1)+"--");
start = i+1;
}
}
start = 0;
// using s.substring(start,i) trims off the extra space between the words.
for(int i = 0;i<s.length();i++){
ch = s.charAt(i);
if(Character.isWhitespace(ch)){
System.out.println(
"--"+s.substring(start,i)+"--");
start = i+1;
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run