-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathConsonent_OddPosition.java
47 lines (41 loc) · 1.2 KB
/
Consonent_OddPosition.java
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
/* Find the characters in odd position of a string which are consonent
*
* Input: Arijit Ghosh
* Output: hs
*/
import java.util.Scanner;
public class Consonent_OddPosition {
/*
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String v = "aeiouAEIOU";
for (int i = 0; i < s.length(); i++) {
if((i+1)%2!=0 && !v.contains(Character.toString(s.charAt(i))) && s.charAt(i)!=' ')
{
System.out.print(s.charAt(i));
}
}
}
*/
// Another Solution
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char[] ch = {'a', 'e', 'i', 'o', 'u', 'A','E', 'I', 'O', 'U'};
for (int i = 0; i < s.length(); i++) {
boolean test = true;
for (int j = 0; j < ch.length; j++) {
if((i+1)%2==0 || s.charAt(i)==ch[j] || s.charAt(i)==' ')
{
test = false;
}
}
if(test == true)
{
System.out.print(s.charAt(i));
}
}
}
}