Home > Java > javaTutorial > Share an example of a classic Java programming question

Share an example of a classic Java programming question

零下一度
Release: 2017-06-25 10:55:27
Original
1375 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template