fpadder.java

来自「JAVA 工作指南 可以说是程序员必备的东西哦」· Java 代码 · 共 29 行

JAVA
29
字号
//1.1 and later

import java.text.DecimalFormat;

public class FPAdder {
    public static void main(String[] args) {

	int numArgs = args.length;

	//this program requires at least two arguments on the command line
        if (numArgs < 2) {
            System.out.println("This program requires two command-line arguments.");
        } else {
	    double sum = 0.0;

	    for (int i = 0; i < numArgs; i++) {
                sum += Double.valueOf(args[i]).doubleValue();
	    }

	    //format the sum
	    DecimalFormat myFormatter = new DecimalFormat("###,###.##");
	    String output = myFormatter.format(sum);

	    //print the sum
            System.out.println(output);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?