java學習(五)java類繼承
阿新 • • 發佈:2017-06-11
author java學習 dex int demo [] color javac print
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類繼承