将字符串从args [0]转换为char然后填充并打印带有字符的2d数组

时间:2013-04-11 06:44:48

标签: java string multidimensional-array char

public static void main(String[] args) {

    String input = args[0]; 

    String [] part = input.split(" "); 
    //splits string into 2 parts (action and characters to encode)
    String action = part[0];
    // action is what is done to letter i.e. decrypt or encrypt
    String plainText = part[0];
    char [] letters = plainText.toCharArray();
    //letters is the input of what to act on

        int n = plainText.length();
        //number of letters typed
        int boxsize; // overall size of box  
        boxsize = (int) Math.pow((Math.sqrt(n))+1,2);
        int Row = (int) Math.sqrt(boxsize); 
        int Col = Row;
        //length of rows AND columns since its square

    if (action.equals("-encrypt")) {

        char [][] box = new char[Row][Col];

        for (int i=0; i<Row; i++) {
        for ( int j=0; j<Col; j++) {

            System.out.println( i );

如果参数以字符串形式给出,如何填充2d char数组? 另外如何打印盒子(数组),使其从左到右垂直向下读取? 例如命令行将是“-encrypt abcd”(不包括引号) 我想要的输出是“acbd”

1 个答案:

答案 0 :(得分:0)

String plainText = part[1];

复制为0

但通常没有引号args [0]将是动作,其余的args [&gt; = 1]间隔为plainText。