geomprogression-geom.html

来自「经典的数据结构源代码(java 实现)」· HTML 代码 · 共 49 行

HTML
49
字号
<html><head><title>Code Fragment</title></head><body text=#000000><center></center><br><br><dl><dd><pre><font color=#ff0080>/** * Geometric Progression */</font><font color=#ff8000>class</font> <font color=#8000a0>GeomProgression </font><font color=#ff8000>extends</font> Progression {  <font color = #ff0080>/** Base. */</font>  <font color=#8000a0><font color=#8000a0>protected</font> </font>long base;  <font color=#ff0080>// Inherits variables first and cur.</font>  <font color = #ff0080>/** Default constructor setting base 2. */</font>  <font color=#0000ff>GeomProgression</font>() {    <font color=#ff8000>this</font><font color=#0000ff></font>(2);  }  <font color=#ff0080>/** Parametric constructor providing the base.   *   * @param b base of the progression.   */</font>  <font color=#0000ff>GeomProgression</font>(long b) {    base = b;    first = 1;    cur = first;  }  <font color=#ff0080>/** Advances the progression by multiplying the base with the current value.   *    * @return next value of the progression   */</font>  <font color=#8000a0><font color=#8000a0>protected</font> </font>long <font color=#0000ff>nextValue</font>() {    cur *= base;    <font color=#8000a0><font color=#ff8000>return</font> </font>cur;  }  <font color=#ff0080>//  Inherits methods firstValue() and printProgression(int).</font>}</dl></body></html>

⌨️ 快捷键说明

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