How can Java take an * from String args and print it out. I tried handling it with the commented portion of this code but it did not work.
Input: 1430 - 110 * 2A + 10
Outputs: 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. You should embrace your arguments by quotation marks to avoid that:
Input: "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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.