-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordManipulator.java
More file actions
58 lines (51 loc) · 1.42 KB
/
WordManipulator.java
File metadata and controls
58 lines (51 loc) · 1.42 KB
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
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
class WordManipulator {
String word;
int len;
WordManipulator() {
word = "";
}
void readWord() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word");
word = sc.nextLine();
word = word.toLowerCase();
len = word.length();
}
void shiftCons() {
String cons = "";
String vowl = "";
for (int i = 0; i < len; i++) {
char ch = word.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
vowl = vowl + ch;
else
cons += ch;
}
word = cons + vowl;
System.out.println("Shifted Word=" + word);
}
void changeWord() {
String sr = "";
word = word.toUpperCase();
for (int i = 0; i < len; i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
ch = (char) ((int) ch + 32);
sr = sr + ch;
} else
sr = sr + ch;
}
System.out.println("Changed word=" + sr);
}
void show() {
System.out.println("Original word=" + word);
}
public static void main(String[] args) {
WordManipulator ob = new WordManipulator();
ob.readWord();
ob.show();
ob.shiftCons();
ob.changeWord();
}
}