Title: There are n integers, so that they move backward in the order of the first number of M positions, the last m number becomes the first number of M
Analysis: Implementation of the move is actually the operation of the index, the array element has not changed, and the index value has changed,
Rational use of% operation, original array index%len= index of original array--(original array index + move number)%len= new array index
Public Static voidFunction01 () {int[] array={2,3,4,6,7,9}; //copy an array for storing the data int[] arraycopy=arrays.copyof (array, array.length); System.out.println ("Original array:"); System.out.println (arrays.tostring (array)); System.out.println ("Please enter the number of digits to move:"); Scanner SC=NewScanner (system.in); intMovenum=sc.nextint ();//number of bits moved for(inti = 0; i < arraycopy.length; i++) { intMove= (i+movenum)%Array.Length; Arraycopy[move]=Array[i]; } System.out.println (Arrays.tostring (arraycopy)); }
Original array:
[2, 3, 4, 6, 7, 9]
Please enter the number of digits to move:
3
[6, 7, 9, 2, 3, 4]
Move implementation of element position in array