4.22 The perfection of the tool class

Source: Internet
Author: User

/* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.