Program to find the XOR of ASCII values of characters in a string | Java program to find XOR of ASCII value of characters in String ; Function to find the XOR of ASCII value of characters in String ; store value of first character ; Traverse String to find the XOR ; Return the XOR ; Driver code
class GFG { static int XorAscii ( String str , int len ) { int ans = ( str . charAt ( 0 ) ) ; for ( int i = 1 ; i < len ; i ++ ) { ans = ( ans ^ ( ( str . charAt ( i ) ) ) ) ; } return ans ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int len = str . length ( ) ; System . out . print ( XorAscii ( str , len ) + "NEW_LINE"); str = " GfG " ; len = str . length ( ) ; System . out . print ( XorAscii ( str , len ) ) ; } }