3-24java的日子

来源:互联网 发布:js修改style display 编辑:程序博客网 时间:2024/05/16 11:34

//n位数组移位m位:

想想有点惭愧,今天的进步不大有点,加油,不受影响,步步为营。时间紧迫啊,路还很长长


public class ShuZuYiWei {

public void Fun() {
int n = 0;
int kaishi=0;
int weishu=5;
int[] a = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("移位前的数组:");
for (int i = 0; i<= a.length - 1; i++) {
System.out.print(a[i]+"\t");
}

for(int j=0;j<weishu;j++){
n = a[a.length - 1];
for (int i = a.length - 1; i >= 1; i--) {
a[i] = a[i - 1];
}
a[0] = n;
}

System.out.println();
System.out.println("移位后的数组:");
for (int i = 0; i<= a.length - 1; i++) {
System.out.print(a[i]+"\t");
}
}
public static void main(String[] args){
new ShuZuYiWei().Fun();
}
}
原创粉丝点击