简体   繁体   English

Java String args asterisk

[英]Java String args asterisk

How can Java take an * from String args and print it out. Java如何从String args中取出*并将其打印出来。 I tried handling it with the commented portion of this code but it did not work. 我尝试使用此代码的注释部分处理它,但它不起作用。

Input: 1430 - 110 * 2A + 10 输入:1430 - 110 * 2A + 10

Outputs: 1430-110.classpath.project.settingsbinsrc2A+10 输出:1430-110.classpath.project.settingsbinsrc2A + 10

import java.io.*;

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
    for(int i=0; i<args.length; i++) {
        System.out.print(args[i]);

        /*

        if(args[i].equals(".classpath.project.settingsbinsrc")) {
            args[i] = "*";
        }

        */

    }

}

}

Your shell expands the asterisk (*) to the list of files in your current directory. 您的shell将星号(*)扩展为当前目录中的文件列表。 You should embrace your arguments by quotation marks to avoid that: 你应该用引号来包含你的参数,以避免这种情况:

Input: "1430 - 110 * 2A + 10" 输入:“1430 - 110 * 2A + 10”

I think You are looking for something like this: 我想你正在寻找这样的东西:

public static void main(String[] args)  {
    String str = "";
    for(int i=0; i<args.length; i++) {
        System.out.print(args[i]);
        str=str.concat(args[i]);
    }
    str = str.replaceAll(".classpath.project.settingsbuildejbModule", "*");
    System.out.println();
    System.out.println(str);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM