java學習(五)java類繼承

來源:互聯網
上載者:User

標籤:rgs   產生   else   最大   javac   java學習   製作   javadoc   void   

1.製作一個工具類的文檔

  javadoc -d 目錄 -author -version   arrayTool.java

 執行個體:

  

class arrayDemo{   public static void main(String[] args){              int[] arr = {23,34,54,65,57,7};           //遍曆數組       arrayTool.printArray(arr);       //擷取數組中的最大值       int max = arrayTool.getMax(arr);       System.out.println("數組中的最大值為"+max);       //擷取數組中元素的索引       int index = arrayTool.getIndex(arr,57);       System.out.println("57在數組中的索引位置為"+index);   }}

產生工具類的文件類型
javac -d doc -author -version arrayTool.java

/**
*數組操作工具類 *@author greymouster *@version v1.0 */public class arrayTool{ /** *私人的構造方法 禁止外部執行個體化對象 */ private arrayTool(){} /** *遍曆數組方法 遍曆後為[元素1,元素2,元素3,....] *@param arr 要遍曆的數組 */ public static void printArray(int[] arr){ System.out.print("["); for(int x=0;x<arr.length;x++){ if(x == arr.length-1){ System.out.println(arr[x]+"]"); }else{ System.out.print(arr[x]+","); } } } /** *擷取數組中最大值的方法 *@param arr 數組 *@return 返回數組中的最大值 */ public static int getMax(int[] arr){ //加入數組的元素為最大值 int max = arr[0]; for(int x=1;x<arr.length;x++){ if(max<arr[x]){ max = arr[x]; } } return max; } /** *擷取數組中值的索引 *@param arr 數組 value 數組中的值 *@return index 返回數組中值所在的索引 如果不存在返回-1. */ public static int getIndex(int[] arr,int value){ int index = -1; for(int x=0;x<arr.length;x++){ if(arr[x] == value){ index = x; } } return index; }}

 

java學習(五)java類繼承

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.