문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
이 챌린지에서 할 작업은 모든 테스트 파일들을 실행 했을 때, 코드가 성공하는지 디버그 하는 것이다.
오직 숫자 0과 1만 있는 두 개의 문자열이 주어질때, 두 문자열의 XOR을 찾아라.
HackerRank의 컴파일에 문제가 있는지 해결되지 않는다. 단순히 System.out.println()를 하여도 틀렸다고 나온다.
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner scanner = new Scanner(System.in);
String s1 = scanner.nextLine();
String s2 = scanner.nextLine();
System.out.println(strings_xor(s1, s2));
scanner.close();
}
public static String strings_xor(String s1, String s2){
StringBuilder sb = new StringBuilder();
for(int i = 0; i < s1.length(); i++){
if(s1.charAt(i) == s2.charAt(i)){
sb.append("0");
}else{
sb.append("1");
}
}
return sb.toString();
}
}