码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • java 对多维数组的工具类(比如遍历多维数组工具类)


    目录

    • 1 遍历int类型二维数组
    • 2 使用流遍历int 类型二维数组
    • 3 遍历 float 类型二维数组
    • 4 遍历 double 类型二维数组
    • 5 遍历 int 类型 3维数据
    • 6 遍历 Float 类型 3维数据

    1 遍历int类型二维数组

    public static void printErIntArray(int[][] matrix){
    
            for (int i = 0; i < matrix.length; i++) { //this equals to the row in our matrix.
                for (int j = 0; j < matrix[i].length; j++) { //this equals to the column in each row.
                    System.out.println(matrix[i][j] + " ");
                }
    //            System.out.println("/t"); //change line on console as row comes to end in the matrix.
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    2 使用流遍历int 类型二维数组

     public static void printErIntArrayByStream(int[][] iDim) {
            Arrays.stream(iDim).forEach(i -> {
                Arrays.stream(i).forEach(n -> System.out.println(n));
                System.out.println();
            });
    
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3 遍历 float 类型二维数组

    public static void printErFloatArray(float[][] matrix){
    
        for (int i = 0; i < matrix.length; i++) { //this equals to the row in our matrix.
            for (int j = 0; j < matrix[i].length; j++) { //this equals to the column in each row.
                System.out.println(matrix[i][j] + " ");
            }
    //            System.out.println("/t"); //change line on console as row comes to end in the matrix.
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    4 遍历 double 类型二维数组

    public static void printErDoubleArrayByStream(double[][] matrix){
        Arrays.stream(matrix).forEach(i -> {
            Arrays.stream(i).forEach(n -> System.out.format(Locale.US,"%.2f ", n));
            System.out.println();
        });
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    5 遍历 int 类型 3维数据

      public static void printThreeIntArray(int[][][] arr){
            for(int i=0;i<arr.length;i++) {
                for(int j=0;j<arr[i].length;j++) {        //我们可以把前边想像成一个一维数组
                    if(j==arr[i].length-1) {
                        System.out.println();            //换行
                    }
                    for(int k=0;k<arr[i][j].length;k++)
                        System.out.print(arr[i][j][k]+" ");//遍历三维数组
                }
            }
    
    
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    6 遍历 Float 类型 3维数据

        public static void printThreeFloatArray(float[][][] arr){
            for(int i=0;i<arr.length;i++) {
                for(int j=0;j<arr[i].length;j++) {        //我们可以把前边想像成一个一维数组
                    if(j==arr[i].length-1) {
                        System.out.println();            //换行
                    }
                    for(int k=0;k<arr[i][j].length;k++)
                        System.out.print(arr[i][j][k]+" ");//遍历三维数组
                }
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    C++ Visual Studio 2022 中的改进、行为更改和错误修复
    Java_SpringBoot_MybatisPlus入门
    蜂鸟E203学习笔记(二)--蜂鸟E203总体框架
    Day03 计算机信息的存储
    大学生网页设计模板 静态HTML个人主页网页作业成品 DIV CSS个人介绍主题静态网页
    SSM+电商背景下精品茶网站 毕业设计-附源码191732
    Arduino 学习笔记_4 模拟输入和输出
    Redis 6.0源码学习 RedisObject
    【Windows】VMware虚拟机安装Windows 10 教程
    java计算机毕业设计微留学学生管理系统源程序+mysql+系统+lw文档+远程调试
  • 原文地址:https://blog.csdn.net/python113/article/details/125480361
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号