arraytest-findcount.html
来自「经典的数据结构源代码(java 实现)」· HTML 代码 · 共 22 行
HTML
22 行
<html><head><title>Code Fragment</title></head><body text=#000000><center></center><br><br><dl><dd><pre> <font color = #ff0080>/** Counts the number of times an integer appears in an array. */</font> <font color=#8000a0><font color=#8000a0>public</font> </font><font color=#8000a0>static</font> <font color=#8000a0><font color=#8000a0>int</font> </font><font color=#0000ff>findCount</font>(<font color=#8000a0>int</font>[] a, <font color=#8000a0><font color=#8000a0>int</font> </font>k) { <font color=#8000a0><font color=#8000a0>int</font> </font>count = 0; <font color=#ff8000>for</font><font color=#0000ff> </font>(<font color=#8000a0>int</font> e: a) { <font color=#ff0080>// note the use of the "foreach" loop</font> <font color=#ff8000>if</font><font color=#0000ff> </font>(e == k) <font color=#ff0080>// check if the current element equals k</font> count++; } <font color=#8000a0><font color=#ff8000>return</font> </font>count; }</dl></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?