/* Operations on arrays How to make a manual? A: Write a tool Class B: How do you add a document comment to this class? Add something? C: Parsing document annotations with tools Javadoc tool D: Format javadoc-d directory-author-version Arraytool.java directory: You can write the path of a folder to make a Help document error: Cannot find a public or protected class that can be documented: tells us that the class does not have sufficient permissions */class the Arraydemo {publicly static void main (String [] args) {//define array int[] arr = {28, 55, 37, 46, 19};//Traverse Arraytool.printarray (arr);//Get the most value int max = Arraytool.getmax (arr); System.out.println ("Max:" + max);//Gets the index value of 55 int index = Arraytool.getindex (arr, 55); System.out.println ("index:" + index);}}
/*** This is a tool class for manipulating arrays * @author msirene* @version v.10*/public class arraytool {// The construction method is private, the outside world can not create objects/*** this is a private structure */private arraytool () {}/*** This is the way to iterate over the array, The format after traversal is: [element 1, element 2, element 3, ...] * @param arr This is the array to be traversed */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] + ", ");}} /*** This is the method to get the maximum value in the array * @param arr This is the array to get the maximum value * @return Returns the maximum value in the array */public static int getmax (Int[] arr) {int max = arr[0];for (int x = 1; x < arr.length; x++) {if (Arr[x] > max) { MAX&NBSP;=&NBSP;ARR[X];}} return max;}/*** gets the index of the first occurrence of the specified element in the array, and returns the -1* @param arr found array * @param if the element does not exist value The element to find * @return Returns the index of the element in the array, or -1*/public static int getindex (int[] if it does not exist) Arr, int value) {int index = -1;for (int x = 0; x < arr.length; x++) {if (Arr[x] == value) {index = x;break;}} Return index;}}
4.22 The perfection of the tool class