将字符串从args [0]转换为char,然后填充并使用chars打印2d数组 [英] convert string from args[0] into char then populate and print a 2d array with the chars

查看:182
本文介绍了将字符串从args [0]转换为char,然后填充并使用chars打印2d数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如果参数是以字符串形式给出的,
也是如何打印盒子(数组),使得它从每一列垂直向下读取?\
命令行的eg将是-encrypt abcd(不包括引号)
output i want isacbd

how do you populate a 2d char array if the argument is given as a string? also how do you print the box (array) so that it reads vertically down each column left to right?\ an eg of command line would be "-encrypt abcd" (exclude quotation marks) output i want is "acbd"

推荐答案

String plainText = part[1];

已复制0

没有引号args [0]将是动作,其余args [> = 1]间隔的plainText。

But generally without quotation marks args[0] would be the action, the rest args[>=1] spaced plainText.

这篇关于将字符串从args [0]转换为char,然后填充并使用chars打印2d数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆