File size: 1,996 Bytes
07f7ed0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Write the method

String removeVowels(String word)

which returns a string with all vowels (a, e, i, o, u and y) removed from the string given as a parameter.



You can assume that the word is written entirely in lower case.
Example of a method call:
public static void main(String[] args) {
    String testword = "welcome!";
    System.out.println(removeVowels(testword));
}
Program outputs:
wlcm!



======================================


import java.util.Random;

public class Test{
    public static void main(String[] args){
        final Random r = new Random();
        
        
        String[] words = "first second third fourth programming class method java variable".split(" ");
        for (String word : words) {
            System.out.println("Testing with parameter " + word);
            System.out.println("Without vowels: " + removeVowels(word));
            System.out.println("");
        }
        
    }


    //ADD
    public static String removeVowels(String word) {
        String newWord = "";
        
        // if the character is not a/e/i/o/u/y - then add to newWord
        for (int i = 0; i < word.length(); i++) {
            if (word.charAt(i) != 'a' 
                && word.charAt(i) != 'e' 
                && word.charAt(i) != 'i' 
                && word.charAt(i) != 'o' 
                && word.charAt(i) != 'u' 
                && word.charAt(i) != 'y') {
                    newWord += word.charAt(i);
            }
        }
        return newWord;
    }


    
    
}





Testing with parameter first
Without vowels: frst

Testing with parameter second
Without vowels: scnd

Testing with parameter third
Without vowels: thrd

Testing with parameter fourth
Without vowels: frth

Testing with parameter programming
Without vowels: prgrmmng

Testing with parameter class
Without vowels: clss

Testing with parameter method
Without vowels: mthd

Testing with parameter java
Without vowels: jv

Testing with parameter variable
Without vowels: vrbl