zoukankan      html  css  js  c++  java
  • Java SE学习之数组——匿名数组和不规则数组

    本文是学习网络上的文章时的总结以及自己的一点实践。感谢大家无私的分享。

    近期偶然遇到了数组的问题,学习了匿名数组和不规则数组。

    匿名数组适用于仅仅使用一次的情况;不规则数组适用是每行数据总数不确定的情况。

    以下贴上我的小样例

    package SE;
    
    import java.util.Random;
    
    /**
     * <p>
     * Description: 此方法是对匿名数组和不规则数组的学习
     * </p>
     * @author zhangjunshuai
     * @version 1.0
     * Create Date: 2014-10-24 下午5:49:22
     * Project Name: Java7Thread
     *
     * <pre>
     * Modification History: 
      *             Date                                Author                   Version          Description 
     * -----------------------------------------------------------------------------------------------------------  
     * LastChange: $Date::             $      $Author: $          $Rev: $         
     * </pre>
     *
     */
    public class Array {
    
    	/**
    	 * <p>
    	 * </p>
    	 * @author zhangjunshuai
    	 * @date 2014-10-24 下午5:48:19
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		//1、匿名数组的使用
    		out1(new String[]{"1","2"});
    		out2("3","4");
           //2、不规则数组的使用   
            irregular();
    	}
    
    	/*
    	 * 不规则数组
    	 */
    	static void irregular(){
    		int arrays[][];
    		arrays =  new int[3][];
    		for(int i=0;i<arrays.length;i++){
    			/*Random r = new Random(47);
    			int h =   r.nextInt(13);*/
    			int h =   (int)(Math.random()*16);
    			arrays[i] = new int[h];
    			for(int j=0;j<h;j++){
    				int w =  (int)(Math.random()*100);
    				arrays[i][j] = w;
    			}
    		}
    		//遍历输出
    		for(int i=0;i<arrays.length;i++){  
                
                for(int j=0;j<arrays[i].length;j++){  
                      
                    System.out.print(arrays[i][j]+" ");  
                }  
                System.out.println();  
            }  
    	}
    	static void out1(String[] ss){
    		for (String string : ss) {
    			System.out.print(string);
    		}
    		System.out.println();
    	}
    	static void out2(String... ss){
    		for (String str : ss) {
    			System.out.print(str);
    		}
    		System.out.println();
    	}
    }
    



  • 相关阅读:
    挖矿病毒 netstat与ss重要区别
    leetcode 正则表达式匹配
    DNS重新绑定攻击
    Mac OS ssh 禁用密码登陆
    linux alias 别名在Bash脚本内不起作用 远程执行alias 命令不工作
    centos 7 搭建 l2tp
    psacct 软件包工具监视所有用户执行的命令
    随机密码生成
    Linux 进程 cpu 使用排序 内存 使用排序
    nginx 反向代理 uri 重写
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5109742.html
Copyright © 2011-2022 走看看