zoukankan      html  css  js  c++  java
  • 二维数组的打印,查找等

    二维数组的打印

    public class TwoDimensionalArray {
    
        public static void main(String[] args) {
            int x = 0;
            int[][] a = { { 8, 2, 6, 5 }, { 6, 3, 1, 0 }, { 8, 7, 9, 6 } };
            System.out.print("	 	");
            for (int i = 0; i <= a.length; i++) {
                System.out.print(i + "	");
            }
            System.out.print("
    	" + "-------------------------");
            System.out.println();
            for (int i = 0; i < a.length; i++) {
                System.out.print(i + "  |	");
    
                for (int j = 0; j < a[i].length; j++) {
                    System.out.print(a[i][j] + "	"); // "	"是制表符
                }
                System.out.println();
            }
    
        }
    }
    

     

     

    public class TwoDimensionalArray {
    
        public static void main(String[] args) {
            int[][] a = {{8, 2, 6, 5}, {6, 3, 1, 0}, {8, 7, 9, 6}};
            for (int i=0;i<3;i++)
                System.out.println ( Arrays.toString (a[i]));
    
        }
    }
    

      

     

    二维数组的查找

    public class Array {
    
            public static boolean find(int [][] arry,int num){
                int column=arry[0].length-1;
                int row=0;
                while(row<arry.length&&column>=0){
                    if(num==arry[row][column]){
                        return true;
                    }
                    if(arry[row][column]>num){
                        column--;
                    }else{
                        row++;
                    }
    
                }
                return false;
            }
    
            public static void main(String[] args) {
                int [][] arry=new int[3][3];
                for(int i=0;i<arry.length;i++){
                    for(int j=0;j<arry[0].length;j++){
                        arry[i][j]=(i+1)*(j+1);
                    }
                }
    
                System.out.println("查看是否有元素9:"+find(arry,9));
                System.out.println("查看是否有元素10:"+find(arry,10));
            }
    
        }
    

     

    public class TwoDimensionalArray {
    
        int[][] a = {{8, 2, 6, 5}, {6, 3, 1, 0}, {8, 7, 9, 6}};
    
        public static boolean find(int[][] arry, int num) {
            int column = arry[0].length - 1;
            int row = 0;
            while (row < arry.length && column >= 0) {
                if (num == arry[row][column]) {
                    return true;
                }
                if (arry[row][column] > num) {
                    column--;
                } else {
                    row++;
                }
    
            }
            return false;
        }
    
        public static void print(int[][] a) {
            int x = 0;
    
            System.out.print("	 	");
            for (int i = 0; i <= a.length; i++) {
                System.out.print(i + "	");
            }
            System.out.print("
    	" + "-------------------------");
            System.out.println();
            for (int i = 0; i < a.length; i++) {
                System.out.print(i + "  |	");
    
                for (int j = 0; j < a[i].length; j++) {
                    System.out.print(a[i][j] + "	"); // "	"是制表符
                }
                System.out.println();
            }
        }
    
        public static void main(String[] args) {
            int[][] arry = new int[3][3];
            for (int i = 0; i < arry.length; i++) {
                for (int j = 0; j < arry[0].length; j++) {
                    arry[i][j] = (i + 1) * (j + 1);
                }
            }
            print(arry);
            System.out.println();
            System.out.println("查看是否有元素9:" + find(arry, 9));
            System.out.println("查看是否有元素10:" + find(arry, 10));
        }
    }
    

      

     偶数

    public class OddTest {
    
            public static void main(String[] args) {
                boolean odd = true;// 奇数行标志
                for (int i = 2; i <= 50; i += 2) {
                    System.out.print(odd ? i + "	A	" : "A	" + i + "	");
                    if (i % 10 == 0) {
                        System.out.println();
                        odd = !odd;
                    }
                }
            }
    }
    

     

     

  • 相关阅读:
    CentOS 7安装NXLog服务
    CentOS 7下Nginx日志的定时拆分
    IIS服务器配置NXLog进行syslog转发(并解决GMT+8小时时差问题)
    Linux服务器和Nginx配置syslog转发
    CentOS 7下安装Slowhttptest DDoS检测工具
    接口自动化:六.pytest写用例
    linux: CentOs 环境下搭建nginx负载均衡
    linux: CentOs 环境下搭建nginx
    环境搭建:linux下tomcat接口测试环境部署
    环境搭建:linux环境下安装mysql数库
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/11346783.html
Copyright © 2011-2022 走看看