XOR Strings 2

  • + 0 comments

    Here is the solution for XOR Strings 2 in Java7 because for Java 8 they did not give any code to modify but we have to modiy only 3 lines according to question.

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static String stringsXOR(String s, String t) {
        String res = new String("");
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) != t.charAt(i))
                res += "1";
            else
                res += "0";
        }
    
        return res;
    }
    
    public static void main(String[] args) {
    
        String s, t;
        Scanner in = new Scanner(System.in);
        s = in.nextLine();
        t = in.nextLine();
        System.out.println(stringsXOR(s, t));
    
    }
    

    }