如何将 char 1d 数组转换为 2d 数组,然后通过一次读取每一列来打印 2d 数组。即使用参数“-encrypt abcd”
public class CHARSTRING {
public static void main(String[] args) {
String encrypt = args[0];
String letters = args[1];
//length of letters to be encrypted
int n = letters.length();
char Rows [] = letters.toCharArray();
if (encrypt.equals("-encrypt")) {
if ( (n*n)/n == n) {
int RootN = (int) Math.sqrt(n); //find depth and width of 2d array
char [][] box = new char [RootN][RootN]; //declare 2d array
for (int i=0; i<RootN; i++) {
for (int j=0; j<RootN; j++) {
box[i] = Rows;
System.out.println(Rows);
//输出4行:abcd
但我试图让输出为“acbd”