码农知识堂 - 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
  • 相关阅读:
    aarch64 麒麟v10系统使用docker部署nvidia_gpu_exporter监控GPU
    非关系型数据库MongoDB是什么/SpringBoot如何使用或整合MongoDB
    java计算机毕业设计Vue框架校园相约健康运动平台源码+mysql数据库+系统+lw文档+部署
    asp.net购物网站源码-系统销售毕业设计
    【LittleXi】ICPC2023 南京站 总结
    上周热点回顾(10.3-10.9)
    iOS 通过NSURLProtocol拦截WKWebView网络请求
    PHREEQC建模及典型案例解析与高阶拓展应用【反向“编译”、“玩转”后处理技术、GibbsStudio和PhreePlo方法】
    windows server2012搭建邮箱服务器+客户端界面(hmailserver+afterlogic)+批量创建邮箱
    MySql基础篇——窗口函数和公用表达式
  • 原文地址:https://blog.csdn.net/python113/article/details/125480361
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号