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 }
  • 相关阅读:
    ABP 往前端返回详细的错误信息
    ABP 报错1
    three.js 测试1
    three.js 添加 图形控制界面 gui
    three.js 设置透明度
    three.js 基础使用1
    three.js 添加环境光
    three.js 添加三维坐标系
    P2690 接苹果
    [USACO08FEB]修路Making the Grade
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/6544447.html
Copyright © 2011-2022 走看看