sumprices.java
来自「Java 入门书的源码」· Java 代码 · 共 15 行
JAVA
15 行
/* The recursive sum method sums the elements
* from start to end of the array passed to it.
*/
public class SumPrices {
public static double sum(double[] p, int start, int end) {
if (start < end)
return p[start] + sum(p,start+1,end);
else return 0;
}
public static void main(String[] args) {
double[] prices = {12.23, 3.68, 34.99, 8.87, 63.99};
System.out.println("The sum is $" + sum(prices,0,prices.length));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?