-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaySeven.java
More file actions
28 lines (24 loc) · 866 Bytes
/
Copy pathDaySeven.java
File metadata and controls
28 lines (24 loc) · 866 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
import java.util.ArrayList;
public class DaySeven{
public static void main(String[] args){
String sentence = "This is an example";
String eachWord = "";
String reverse = "";
for (int count = 0; count < sentence.length(); count++){
char letter = sentence.charAt(count);
eachWord += letter;
if (letter == ' '){
for (int counter = eachWord.length()-2; counter >= 0; counter--){
char letterTwo = eachWord.charAt(counter);
reverse += letterTwo;
}
reverse += " ";
eachWord = "";
}
}
for(int count = eachWord.length()-1; count >= 0; count--){
reverse += eachWord.charAt(count);
}
System.out.println(reverse);
}
}