zoukankan      html  css  js  c++  java
  • shiyan9


    1. 打乱行
    编写一个方法打乱一个二维整型数组的行:
    public static void shuffle(int[][] m)
    编写一个测试程序,打乱下面的矩阵:
    Int[][] m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}};

    package com.cust.daluan;

    import java.util.Scanner;

    public class test {
    public static void main(String[] args){
    Scanner scan = new Scanner(System.in);


    int[][] m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}};
    while (true){
    System.out.println("原来的数组是");
    for(int i=0;i<5;i++){
    for(int j=0;j<2;j++){
    System.out.print(m[i][j]+" ");
    }
    System.out.println();
    }
    System.out.println("输入要打断的行a b");
    int a = scan.nextInt()-1;
    int b = scan.nextInt()-1;
    tools t=new tools();
    t.mix(m, a, b);
    System.out.println("打乱之后是");
    for(int i=0;i<5;i++){
    for(int j=0;j<2;j++){
    System.out.print(m[i][j]+" ");
    }
    System.out.println();
    }
    }
    }

    }

    package com.cust.daluan;

    public class tools {
    public void mix(int[][] m,int a,int b){
    int hang= m.length;
    int lie=m[0].length;
    if(a+1>hang||b+1>hang){
    System.out.println("error");

    }else{
    int[] temp=new int[lie];
    temp=m[a];
    m[a]=m[b];
    m[b]=temp;
    }

    }

    }

  • 相关阅读:
    ubuntu12.04启动系统时报错
    TCP&HTTP协议详解
    nginx日志分析、切割与防盗链
    Nginx Rewrite规则详解
    nginx location深入剖析
    hadoop自动安装脚本
    极易中文分词
    朴素贝叶斯算法分析及java 实现
    随机森林(Random Forest)
    ubuntu 13.04 安装 JDK
  • 原文地址:https://www.cnblogs.com/helloaworld/p/6084495.html
Copyright © 2011-2022 走看看