有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将字符串从args[0]转换为char,然后使用chars填充并打印二维数组

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字符数组? 另外,如何打印框(数组),使其从左到右垂直向下读取每列\ 命令行的一个示例是“-encrypt abcd”(不包括引号) 我想要的输出是“acbd”


共 (1) 个答案

  1. # 1 楼答案

    String plainText = part[1];
    

    已使用0复制

    但通常情况下,没有引号的args[0]将是操作,其余args[>;=1]为空格的纯文本