-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversWordString.java
More file actions
49 lines (35 loc) · 931 Bytes
/
ReversWordString.java
File metadata and controls
49 lines (35 loc) · 931 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package questions2;
import java.util.Scanner;
public class ReversWordString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter tha word");
String s = sc.nextLine();
// Logic 1
String[] words = s.split(" ");
String reversString = "";
for(String w : words) {
String reversword ="";
for(int i= w.length()-1; i>=0; i--) {
reversword = reversword + w.charAt(i);
}
reversString = reversString + reversword + " ";
}
System.out.println("Reverse of Word :"+ reversString);
// Logic 2
//
// String[] words= s.split("\\s");
//
// String reversword = "";
//
// for(String w : words) {
//
// StringBuffer sb = new StringBuffer(w);
// sb.reverse();
//
// reversword = reversword + sb.toString() + " ";
// }
//
// System.out.println("Reverse of Word :"+ reversword);
}
}