zoukankan      html  css  js  c++  java
  • ArrayInt

    public class ArrayInt {
        public static void main(String [] args){
            stringEqual();
            arrayIntDot();
            System.out.println("--------------------------------------------------------------------------");
            arrayInt();
            System.out.println("--------------------------------------------------------------------------");
            arrayIntOne();
            System.out.println("--------------------------------------------------------------------------");
        }
    
        private static void stringEqual() {
            String str1=new String ("str");
            String str2=new String ("str");
            System.out.println(str1==str2);
            String str3="str";
            String str4="str";
            System.out.println(str3==str4);
        }
    
        private static void arrayIntDot() {
            String s="1,2,3,4;5,6,7,8;9,10,11,12,13";
            //以split()方法 分解
            String[] sFirst=s.split(";");
            String[][] word=new String[sFirst.length][];
            int flag=0;
            for(int i=0;i<sFirst.length;i++){
                String[] sSecond=sFirst[i].split(",");
                System.out.println("sSecond length:"+sSecond.length);
                word[i]=new String[sSecond.length];//这步确定行不规则数组的每行长度
                //为这个数组赋值
                for(int j=0;j<sSecond.length;j++){
                    word[i][j]=sSecond[j];
                }
                System.out.println("---------------这是第"+(i+1)+"次循环-------------------");
            }
            //输出二维数组
            System.out.println("输出二维数组-------------------");
            for(int i=0;i<word.length;i++){
                for(int j=0;j<word[i].length;j++){
    
                    System.out.print(word[i][j]+" ");
                }
                System.out.println();
            }
        }
    
        private static void arrayInt() {
            int [][] arrayTemp={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
            for(int i=0;i< arrayTemp.length;i++){
                for (int j=0;j<arrayTemp[i].length;j++){
                    System.out.println(arrayTemp[i][j]+" ");
                }
            }
        }
    
        public static void arrayIntOne(){
            //0  1 2 3可以不换行?
            int arrayTemp[][];
            arrayTemp=new int[3][];
            arrayTemp[0]=new int[4];
            arrayTemp[1]=new int[4];
            arrayTemp[2]=new int[4];
            for(int i=0;i< arrayTemp.length;i++){
                for (int j=0;j<arrayTemp[i].length;j++){
                    arrayTemp[i][j]=j;
                    System.out.println(arrayTemp[i][j]+" ");
                }
                System.out.println();
            }
        }
    }
  • 相关阅读:
    招行面试
    今日头条面试[教育岗]
    四方精创 面试
    ArrayList 源码
    redis缓存,穿透,击穿,雪崩
    hashMap
    集合整理
    阿里CBU技术部一面
    网安面试
    php递归获取顶级父类id
  • 原文地址:https://www.cnblogs.com/buffercache/p/14035798.html
Copyright © 2011-2022 走看看