Modify characters of a string by adding integer values of same | Java program for the above approach ; Function to modify a given String by adding ASCII value of characters from a String S to integer values of same indexed characters in String N ; Traverse the String ; Stores integer value of character in String N ; Stores ASCII value of character in String S ; If b exceeds 122 ; Replace the character ; Print resultant String ; Driver Code ; Given Strings ; Function call to modify String S by given operations
import java . util . * ; class GFG { static void addASCII ( char [ ] S , char [ ] N ) { for ( int i = 0 ; i < S . length ; i ++ ) { int a = ( int ) ( N [ i ] ) - '0' ; int b = ( int ) ( S [ i ] ) + a ; if ( b > 122 ) b -= 26 ; S [ i ] = ( char ) ( b ) ; } System . out . print ( S ) ; } public static void main ( String [ ] args ) { String S = " sun " , N = "966" ; addASCII ( S . toCharArray ( ) , N . toCharArray ( ) ) ; } }