⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sumprices.java

📁 Java 入门书的源码
💻 JAVA
字号:
/* 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -