-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseWords.java
More file actions
executable file
·32 lines (31 loc) · 976 Bytes
/
ReverseWords.java
File metadata and controls
executable file
·32 lines (31 loc) · 976 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
/**
Answer For
https://practice.geeksforgeeks.org/problems/reverse-words-in-a-given-string/0/?ref=self
**/
import java.util.Scanner;
public class ReverseWords {
public static void main(String[] args){
Scanner inpScanner=new Scanner(System.in);
int testCaseCounter=inpScanner.nextInt();
int count=0;
String[] unReversedString=new String[testCaseCounter];
String[] reversedString=new String[testCaseCounter];
inpScanner.nextLine();
while(count<testCaseCounter){
unReversedString[count]=inpScanner.nextLine();
String []splitWthDat=unReversedString[count].split("\\.");
reversedString[count]="";
for(int i=splitWthDat.length-1;i>=0;i--){
if (i==0){
reversedString[count]=reversedString[count]+splitWthDat[i];
}else{
reversedString[count]=reversedString[count]+splitWthDat[i]+".";
}
}
count++;
}
for (int i=0;i<testCaseCounter;i++){
System.out.println(reversedString[i]);
}
}
}