- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReverseWordExample.java
More file actions
Latest commit
27 lines (25 loc) · 952 Bytes
/
Copy pathReverseWordExample.java
File metadata and controls
27 lines (25 loc) · 952 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
packagecom.codinginterview;
importjava.util.Scanner;
publicclassReverseWordExample {
publicstaticvoidmain(String[] args) {
System.out.println("Reverse a Word from the Sentence Example");
Scannersc = newScanner(System.in);
System.out.println("Enter a String ::");
Stringstr = sc.next();
System.out.println("String Before ::"+ str);
System.out.println("String After ::"+ reverseWord1(str));
}
privatestaticStringreverseWord1(Stringsentance){
sentance = "Dharmendra Kumar Sahu";
String[] strArr = sentance.split(" ");
StringreverseString = "";
for (Stringstr : strArr){
StringreverseWord = "";
for(inti = str.length() - 1; i>=0; i--){
reverseWord = reverseWord + str.charAt(i);
}
reverseString = reverseString + reverseWord + " ";
}
returnreverseString;
}
}