zoukankan      html  css  js  c++  java
  • 36 有n个整数,使其前面各数顺序向后移n个位置,最后m个数变成最前面的m个数

    题目:有n个整数,使其前面各数顺序向后移n个位置,最后m个数变成最前面的m个数

     1     public class _036ExchangeSite {
     2 
     3     public static void main(String[] args) {
     4         exchangeSite();
     5     }
     6 
     7     private static void exchangeSite() {
     8         int N = 10;
     9         int[] a = new int[N];
    10         Scanner scanner = new Scanner(System.in);
    11 
    12         System.out.println("请输入10个整数 :");
    13         for (int i = 0; i < N; i++) {
    14             a[i] = scanner.nextInt();
    15         }
    16 
    17         System.out.println("你输入的数组为 :");
    18         for (int i = 0; i < N; i++) {
    19             System.out.print(a[i] + " ");
    20         }
    21 
    22         System.out.println("
    请输入向后移动的位数 :");
    23         int m = scanner.nextInt();
    24         int[] b = new int[m];
    25         for (int j = 0; j < m; j++) {
    26             b[j] = a[N - m + j];
    27         }
    28 
    29         for (int k = N - 1; k >= m; k--) {
    30             a[k] = a[k - m];
    31         }
    32 
    33         for (int l = 0; l < m; l++) {
    34             a[l] = b[l];
    35         }
    36 
    37         System.out.println("位移后的数组是 :");
    38         for (int n = 0; n < N; n++) {
    39             System.out.print(a[n] + " ");
    40         }
    41     }
    42 }
  • 相关阅读:
    软件安装
    ARIMA
    解决数据分析中的小知识点及问题
    Django详解之路由系统、中间件
    hdoj 1018
    程序员编程技术迅速提高终极攻略 (转自csdn)
    chapter 5:一个简单的规律问题。
    chapter 4:贪心
    7种qsort排序方法
    chapter 2:hdoj 1031(结构体的使用)
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/6544447.html
Copyright © 2011-2022 走看看