Hello members of the forum, something will not come to me how to implement a function. Its task is as follows: There are two arrays:

char[] sentence = new char[]{'袧','袝',' ','袩','袨','袥','校','效','袗','袝','孝','小','携'}; char[] gamma = new char[]{'小','袥','袨','袙','袨'}; 

Depending on the length of the sentence, I need to get an array of the following form:

 char[] result = new char[]{'C','袥','袨','袙','袨','小','袥','袨','袙','袨','小','袥','袨'}; 

Does anyone have any idea how to do this better?

    1 answer 1

    Here is a simple example, you must enter an additional counter:

      char[] sentence = new char[]{'袧','袝',' ','袩','袨','袥','校','效','袗','袝','孝','小','携'}; char[] gamma = new char[]{'小','袥','袨','袙','袨'}; char[] result = new char[sentence.length]; int countForGamma = 0; for (int i = 0; i < sentence.length; i++) { result[i] = gamma[countForGamma]; countForGamma++; if (countForGamma == gamma.length) { countForGamma = 0; } } 
    • Thank you so much for the help. - Andrew