-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringManipulation.java
48 lines (43 loc) · 1.41 KB
/
StringManipulation.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
46
47
48
/* Name: Yujin Bae
Date: February 4, 2022
Teacher: Ms. Krasteva
Program Description: compares two strings regardless of case
*/
public class StringManipulation {
public static void main(String [] args) {
System.out.println(compareRegardlessCase("hahAh", "HaHah"));
}
public static boolean compareRegardlessCase (String strA, String strB) {
boolean equal = true; //for now
int length = strA.length();
//see if the two strings have equal length
if (length == strB.length()){
for (int i = 0; i<length; i++){
char a = strA.charAt(i);
char b = strB.charAt(i);
//if the char a is uppercase, change it to lowercase
if ( a >= 'A' && a <= 'Z')
{
a+=32;
}
//if the char b is uppercase, change it to lowercase
if ( b >= 'A' && b <= 'Z')
{
b+=32;
}
if (a != b){
equal = false;
}
}
} else //if the strings aren't equal in length
{
equal = false;
}
//return thye result
if (equal == false){
return false;
} else {
return true;
}
}//end
}//end of class