Questions about the * number when Java passes a value to the Main method

Source: Internet
Author: User

The existing requirements are as follows:

The value of a simple expression is obtained by means of a cmd.

For example, enter Java Expression 3 + 4

The results are: 7

Code:

Import Java.text.DecimalFormat;

public class Expression {

public static void Main (string[] args) throws Exception {
if (args = = NULL | | Args.length! = 3) {

MyException is simply a succession of exception, which can be regarded as exception. (This is because of the special requirements on the topic, please ignore ...) )
throw new MyException ("Incorrect parameter format");
}

Left-hand operand in expression
Double left = double.valueof (Args[0]);

Operator: + 、-、 *,/
String operate = args[1];

Right operand
Double right = double.valueof (args[2]);
Result of Operation
Double result;


Switch (operate) {
Case "+":
result = left + right;
Break

Case "-":
result = Left-right;
Break

Case "*":
result = left * right;
Break

Case "/":
result = Left/right;
Break

Default
throw new MyException ("Incorrect parameter format");
}

System.out.println (New DecimalFormat ("0.00"). Format (result);
}
}

Operation Result:

Found problems with the program only if the operator is an * number

Modify the program to output the args array entered as: 2 * 3 o'clock

if (args! = null) {
for (int i = 0;i < args.length;i++) {
System.out.println (Args[i]);
}
}

found that when the input parameter is ' * ', there is a lot of data in the args array

The comparison found that the names of all the files under the Java file path were duplicated

So, when you pass a value to the Main method, enter the * number to add the names of all the files in the Java file path to the args array.

The question about the * number when Java passes a value to the Main method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.