我试图从 2d 字符数组中打印字符,但是我不断返回一个字符串而不是每个字母。例如命令行中的参数是
“-加密 abcdefghij”
String command = args[0];
String Text = args[1]; //letters to be
char letters [] = Text.toCharArray();
int m = Text.length(); //number of letters to be decrypted/encrypted
String command = args[0];
String Text = args[1]; //leters to be
char letters [] = Text.toCharArray();
int m = Text.length(); //number of letters to be decrypted/encrypted
if (command.equals("-encrypt")) {
//if statement was here before for perfect square numbers
else if ( m / (int) Math.sqrt(m) != Math.sqrt(m) ) { //non perfect square digits
int RootM = (int) Math.pow((Math.sqrt(m))+1,2); //overall size of 2d array (depth*width)
int RootN1 = (int) Math.sqrt(RootM); //length of rows & columns
char [][] box = new char [RootN1][RootN1]; //define dimensions of 2d array
for (int i=0; i<RootN1; i++) {
for (int j=0; j<RootN1; j++) {
box[i][j]=letters[2*i+j];
}
}
for (int i=0; i<RootN1; i++) {
for (int j=0; j<RootN1; j++) {
System.out.print(box[j][i]);