0
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 );

引数が文字列として与えられた場合、どのように 2 次元の char 配列を設定しますか? また、ボックス (配列) を印刷して、各列を左から右に垂直に読み取るにはどうすればよいですか? \ コマンド ラインの例は、「-encrypt abcd」(引用符を除く) のようになります。必要な出力は「acbd」です。

4

1 に答える 1

0
String plainText = part[1];

0 でコピーされました

しかし、通常、引用符がなければ args[0] がアクションになり、残りの args[>=1] はスペースを空けてプレーンテキストになります。

于 2013-04-11T06:59:45.693 に答える