-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintReverseWord.java
More file actions
43 lines (32 loc) · 835 Bytes
/
PrintReverseWord.java
File metadata and controls
43 lines (32 loc) · 835 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
package examples;
import java.util.Scanner;
public class PrintReverseWord {
public static void main(String[] args) {
String a, lW = null;
int maxLength = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter Line - ");
a = sc.nextLine();
System.out.print("Seperate Reverse Words - ");
String arr[] = a.trim().split(" ");
for (String s : arr) {
for (int i = s.length() - 1; i >= 0; i--) {
System.out.print(s.charAt(i));
}
System.out.print(" ");
}
for (String s : arr) {
if (s.length() > maxLength) {
maxLength = s.length();
lW = s;
}
}
System.out.println("\nLongest Word - " + lW + "(" + lW.length() + ")");
System.out.print("Replacing 'e' with 'a' - ");
for (String s : arr) {
a = s.replace('e', 'a');
System.out.print(a + " ");
}
sc.close();
}
}