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();
            }
        }
    }
  • 相关阅读:
    Twitter Storm安装配置(Ubuntu系统)单机版
    Ubuntu下安装配置JDK1.7
    JS性能优化
    JavaScript禁用页面刷新
    pomelo获取客户端IP
    MySQL数据库工具类之——DataTable批量加入MySQL数据库(Net版)
    MySQL5.6忘记root密码(win平台)
    清空文件下的SVN控制文件
    Windows平台搭建NodeJs开发环境以及HelloWorld展示—图解
    Unity3D默认的快捷键
  • 原文地址:https://www.cnblogs.com/buffercache/p/14035798.html
Copyright © 2011-2022 走看看