There are n integers, so that the previous numbers are moved backward by m positions, and the last m numbers become the first m numbers.
public class Example36 {
public static void main(String[] args) {
int[] m = { 18, 12, 23, 34, 95, 76, 57, 28, 9 };
moveElement(m, 5);
}
public static void moveElement(int[] m, int n) {
System.out.print("Before shifting The array is: ");
for (int r : m) {
System.out.print(r + " ");
}
if (n <= m. length) {
int[] b = new int[m.length];
for (int i = 0; i < m.length - n; i++) {
b[i + n] = m[i];
}
int j = 0; m[i];
j++;
R: B) {
System.out.print (R + "");
}
} Else {## System.out.print ("\ n Move errors!") # }
}
}
The above is the detailed content of Share an example of a classic Java programming question. For more information, please follow other related articles on the PHP Chinese website!