Im trying to divide up a char String into a char array then print it out into a matrix, I thought I had it figured out but then I realized I got a String mismatch, does anyone know a better way to go about this or where im going wrong in my code? Below are the 3 methods im using to achieve this.
public void Key(){
for(int row=0;row<keyMatrix.length;row++){
for(int col=0;col<keyMatrix[row].length;col++){
for (String x : getParts(polyCipher.translation, 2)) {
keyMatrix[row][col] = x;
}
}
System.out.println();
}
}//Key end
public String printKeyMatrix(){
String keyOut = " J A V A\n";
for (int i = 0; i < PHRASE_KEY.length; i++) {
keyOut += PHRASE_KEY[i] + " ";
for (int j = 0; j < PHRASE_KEY.length; j++) {
keyOut += keyMatrix[i][j] + " ";
}
keyOut += "\n";
}
return keyOut;
}
//Method for dividing up the translation by every nth number(Will alway by the 2nd number for this program)
public static List<String> getParts(String string, int partitionSize) {
List<String> parts = new ArrayList<String>();
int len = string.length();
for (int i=0; i<len; i+=partitionSize)
{
parts.add(string.substring(i, Math.min(len, i + partitionSize)));
}
return parts;
}
Aucun commentaire:
Enregistrer un commentaire