Java Array and sort (Arrays.sort (array name))

Source: Internet
Author: User

Import Java.util.Scanner;

Import Java.util.Arrays;

public class ArrayTest03

{

public static void Main (string[] args)

{

System.out.println ("Please enter the length of the array:");

Input in = new input (); Call class input

int n =in.in_put (); Method of invoking class input In_put

Int[] arr = in.                                    Scanin (n); Call Method Scanin

System.out.println ("-----------sort----------");

Arrays.sort (arr); Array Sort---default ascending

In.print_arr (arr); Call Method Pring_arr

System.out.println ("The maximum value of the array is" +arr[n-1]);

System.out.println ("The minimum value of the array is" +arr[0]);

}

}


Class InPut

{

Public int[] Scanin (int n)//keyboard input is assigned to an array

{

int[] arr = new Int[n];

Scanner in = new Scanner (system.in);

System.out.println ("Start input array value:");

for (int i=0;i<arr.length;i++)

{

System.out.println ("Please enter" + (i+1) + "integer");

Arr[i] = In.nextint ();

}

System.out.println ("-------------Display array Values-----------");

Print_arr (arr); Call Method Print_arr

return arr;

}

int in_put ()//keyboard input integer and return this integer

{

Scanner in = new Scanner (system.in);

int N=in.nextint ();

return (n);

}

void Print_arr (int[] arr)//method of output array

{

for (int i=0;i<arr.length;i++)

{

System.out.print (arr[i]+ "");

}

System.out.println ();

}

}


This article is from the "kick-off Growth record" blog, so be sure to keep this source http://yilesh.blog.51cto.com/3169139/1571457

Java Array and sort (Arrays.sort (array name))

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.