forked from codemistic/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode1704.java
More file actions
32 lines (28 loc) · 851 Bytes
/
Leetcode1704.java
File metadata and controls
32 lines (28 loc) · 851 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
package com.company;
public class Leetcode1704 {
public static void main(String[] args) {
String s="Sohail";
System.out.println(halvesAreAlike(s));
}
static boolean halvesAreAlike(String s) {
int c1 = 0, c2 = 0;
for (int i = 0; i < (s.length() / 2); i++) {
char ch = Character.toUpperCase(s.charAt(i));
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
c1++;
}
}
for (int i = (s.length() / 2); i < s.length(); i++) {
char ch = Character.toUpperCase(s.charAt(i));
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
c2++;
}
}
if(c1==c2){
return true;
}
else {
return false;
}
}
}