The following is done using the A array itself:
Packagearray element K-bit right shift;/*** The array moves to and from the K-bit. 0<k<n * *@authorSeeclanukyo moves a set of arrays to the right by the K-bit, the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n*/ Public classArraymovek { Public Static voidMain (string[] args) {intK = 3; int[] A = {1, 2, 3, 4, 5 }; Arraymovek (A, k); } Public Static voidArraymovek (int[] A,intk) {//Get length intL =a.length; //get the maximum subscript value intMaxindex = L-1; //For loop make end and start change position for(inti = 0; I < K; i++) { //gets the value of the array's maximum subscript intLast =A[maxindex]; for(intj = 0; J < Maxindex; J + +) { //moves the other elements in the array to the right one bit, and the first time gets the maxindex-j 0 for the maxindex itselfA[MAXINDEX-J] = a[maxindex-1-J]; } //pass the last value at the end to the beginning of the arrayA[0] =Last ; } //iterate through the output of a new array for(intx:a) {System.out.print (x+ " "); } }}
Here's the second array: (so it's a lot easier)
Packagearray element K-bit right shift;/*** The array moves to and from the K-bit. 0<k<n * *@authorSeeclanukyo moves a set of arrays to the right by the K-bit, the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n*/ Public classArraymovek { Public Static voidMain (string[] args) {intK = 3; int[] A = {1, 2, 3, 4, 5 }; Arraymovek (A, k); } Public Static voidArraymovek (int[] A,intk) {//Get length intL =a.length; //get the maximum subscript value intMaxindex = L-1; //For loop make end and start change position for(inti = 0; I < K; i++) { //gets the value of the array's maximum subscript intLast =A[maxindex]; for(intj = 0; J < Maxindex; J + +) { //moves the other elements in the array to the right one bit, and the first time gets the maxindex-j 0 for the maxindex itselfA[MAXINDEX-J] = a[maxindex-1-J]; } //pass the last value at the end to the beginning of the arrayA[0] =Last ; } //iterate through the output of a new array for(intx:a) {System.out.print (x+ " "); } }}
Moves a set of arrays to the right K-bit, at the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n