亚洲欧洲国产欧美一区精品,激情五月亚洲色五月,最新精品国偷自产在线婷婷,欧美婷婷丁香五月天社区

      考試首頁(yè) | 考試用書(shū) | 培訓(xùn)課程 | 模擬考場(chǎng) | 考試論壇  
      全國(guó)  |             |          |          |          |          |         
        當(dāng)前位置:計(jì)算機(jī)等級(jí) > 二級(jí)考試 > Java語(yǔ)言程序設(shè)計(jì) > 考試輔導(dǎo) > 文章內(nèi)容
        

      全國(guó)計(jì)算機(jī)等級(jí)考試Java語(yǔ)言程序設(shè)計(jì)輔導(dǎo)(44)

      中華IT學(xué)院   【 】  [ 2016年2月13日 ]

      數(shù)組的元素類(lèi)型和數(shù)組的大小都是確定的,所以當(dāng)處理數(shù)組元素時(shí)候,我們通常使用基本循環(huán)或者foreach循環(huán)。

      示例

      該實(shí)例完整地展示了如何創(chuàng)建、初始化和操縱數(shù)組:

      public class TestArray {
      
         public static void main(String[] args) {
            double[] myList = {1.9, 2.9, 3.4, 3.5};
      
            // 打印所有數(shù)組元素
            for (int i = 0; i < myList.length; i++) {
               System.out.println(myList[i] + " ");
            }
            // 計(jì)算所有元素的總和
            double total = 0;
            for (int i = 0; i < myList.length; i++) {
               total += myList[i];
            }
            System.out.println("Total is " + total);
            // 查找最大元素
            double max = myList[0];
            for (int i = 1; i < myList.length; i++) {
               if (myList[i] > max) max = myList[i];
            }
            System.out.println("Max is " + max);
         }
      }
      

      以上實(shí)例編譯運(yùn)行結(jié)果如下:

      1.9
      2.9
      3.4
      3.5
      Total is 11.7
      Max is 3.5
      分享到:
      本文糾錯(cuò)】【告訴好友】【打印此文】【返回頂部
      將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動(dòng)訪問(wèn)考試網(wǎng) | 復(fù)制本頁(yè)地址,傳給QQ/MSN上的好友 | 申請(qǐng)鏈接 | 意見(jiàn)留言 TOP
      關(guān)于本站  網(wǎng)站聲明  廣告服務(wù)  聯(lián)系方式  站內(nèi)導(dǎo)航  考試論壇
      Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved