-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFindTheDifference.java
More file actions
44 lines (36 loc) · 1.34 KB
/
Copy pathFindTheDifference.java
File metadata and controls
44 lines (36 loc) · 1.34 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
package Online_Code_Samples.Week2;
import java.util.Arrays;
public class FindTheDifference {
public static char findTheDifference(String first, String second){
char result = ' ';
char[] firstWord = first.toCharArray();
char[] secondWord = second.toCharArray();
for( int i = 0; i < firstWord.length; i++ ){
for( int j = 0; j < secondWord.length; j++ ){
if( firstWord[i] == secondWord[j] ){
firstWord[i] = ',';
secondWord[j] = ',';
try{
Thread.sleep(3000);
System.out.println("Iteration " + (i+1));
System.out.println(Arrays.toString(firstWord));
System.out.println(Arrays.toString(secondWord));
System.out.println();
}catch (InterruptedException e){
System.out.println(e.getMessage()); }
break;
}
}
}
for( char found : secondWord ){
if( found != ','){
result = found;
break;
}
}
return result;
}
public static void main(String[] args) {
System.out.println(findTheDifference("aaaaee", "eaabaae"));
}
}