久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      java中不定長(zhǎng)參數(shù)的使用方法

      java中不定長(zhǎng)參數(shù)的使用方法

      java中不定長(zhǎng)參數(shù)的使用方法

      不定長(zhǎng)參數(shù)方法的語(yǔ)法如下:

      返回值 方法名(參數(shù)類型...參數(shù)名稱)

      在參數(shù)列表中使用“…”形式定義不定長(zhǎng)參數(shù),其實(shí)這個(gè)不定長(zhǎng)參數(shù)a就是一個(gè)數(shù)組,編譯器會(huì)將(int…a)這種形式看作是(int[] a)的形式。

      示例:編寫一個(gè)不定長(zhǎng)參數(shù)方法。

      /**  * 定義不定長(zhǎng)參數(shù)方法  *   * @author pan_junbiao  *  */ public class MyTest {     public static int add(int... a)     {         int s = 0;         for (int i = 0; i < a.length; i++)         {             s += a[i];         }         return s;     }       public static void main(String[] args)     {         // 調(diào)用不定長(zhǎng)參數(shù)方法         System.out.println("調(diào)用不定長(zhǎng)參數(shù)方法:" + add(1, 2, 3, 4, 5, 6, 7, 8, 9));         System.out.println("調(diào)用不定長(zhǎng)參數(shù)方法:" + add(1, 2));     } }

      運(yùn)行結(jié)果:

      調(diào)用不定長(zhǎng)參數(shù)方法:45 調(diào)用不定長(zhǎng)參數(shù)方法:3

      (相關(guān)視頻教程分享:java視頻教程)

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)