-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem16.java
42 lines (32 loc) · 910 Bytes
/
Problem16.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package dimikOJ;
import java.util.Scanner;
import java.lang.StringBuilder;
public class Problem16 {
public Problem16() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n = input.nextInt();
input.nextLine();
String[] sentences = new String[n];
for (int i = 0; i < sentences.length; i++) {
sentences[i] = input.nextLine();
}
input.close();
for (int i = 0; i < sentences.length; i++) {
System.out.println(reverseWord(sentences[i]));
}
}
public static String reverseWord(String str) {
String words[] = str.split("\\s");
String reverseWord = "";
for (String w : words) {
StringBuilder sb = new StringBuilder(w);
sb.reverse();
reverseWord += sb.toString() + " ";
}
return reverseWord.trim();
}
}