Array element Copy Reversal learning Note

Source: Internet
Author: User

Tag:package    element    public   

Package com.ctgu.java.exer;public class testarray3 {public static void main (String[] args) {int[] arr = new int[]{12,43,9,0,-65,-99,100,9};int max = arr[0];for (int  i = 1; i < arr.length;i++ ) {if (Max < arr[i]) {max =  arr[i];}} System.out.println ("Maximum array value:"  + max); Int min=arr[0];for (int i = 1;i<  arr.length;i++) {if (Min >arr[i]) {min = arr[i];}} SYSTEM.OUT.PRINTLN ("Array minimum is:"  + min); Int sum = 0;for (int i = 0; i  < arr.length; i++) {sum +=arr[i];} System.out.println ("Sum of:"  +sum);int avg = 0;avg = sum / arr.length; System.out.println ("average:"  +avg );    //  array element copy int [] arr1 =  new int[arr.length];for (Int i = 0 ; i < arr1.length;i++) {arr1[i] = arr[i];} The inverse of the array element//for (int i = 0; i< arr.length/2 ; i++) {//int temp = arr[i];//arr[i] = arr[arr.length-1 - i];//arr[arr.length-1-i]=temp;//}//Inversion 2for (int x  = 0 , y = arr.length - 1; x < y;x++,y--) {int  temp = arr[x];arr[x] = arr[y];arr[y] = temp ;} for (int i = 0; i < arr.length; i++) {System.out.print (arr[i] +  "\ t");}}}


Array element Copy Reversal learning Note

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.