Java Array Rollover

Source: Internet
Author: User

Because the first time to write a blog, and we hope to make progress together and work together.

First, you can

public class Revcarr {public static void main (string[] args) {//TODO auto-generated method Stubint []arr = {11,22,33,44,5 5,66,77};for (int x=0;x<arr.length;x++) {System.out.println (arr[x]);}}}

  

To have a control group, the results of the operation are as follows:

This is the normal array to do is to invert all the numbers. Instead of flipping like this:

public class Revcarr {public static void main (string[] args) {//TODO auto-generated method Stubint []arr = {11,22,33,44,5 5,66,77};for (int x=0;x<arr.length;x++) {//control group SYSTEM.OUT.PRINTLN (arr[x]+ ""); System.out.println ("*");} for (int x=arr.length-1;x>=0;x--) {System.out.println (arr[x]+ "");}}}

Such a rollover, although the result can be turned upside down, but also the arr[0] and other address order is also flipped. But the result is:

So it's best to flip it this way:

public class Revcarr {public static void main (string[] args) {//TODO auto-generated method Stubint []arr = {11,22,33,44,5 5,66,77};for (int x=0;x<arr.length;x++) {System.out.println (arr[x]); System.out.println ("*");} Revcarr (arr);//This is the flip print (arr) of an array in the Flip class;//This is the printout}public static void Revcarr (Int[]arr) {for (int x=0;x< arr.length/2;x++) {int a = Arr[x];arr[x]=arr[arr.length-1-x];arr[arr.length-1-x]=a;}} public static  void print (int. []arr) {for (int x=0;x<arr.length;x++) {System.out.println (arr[x]);}}}

Results:

11*22*33*44*55*66*77*77665544332211

  

Java Array Rollover

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.