【转】Java中二维数组的操作
//1.二维数组的定义
//2.二维数组的内存空间
//3.不规则数组
输出要放在循环里面,放在外面就报错了
打debug确定二维数组的关系
现在程序在7与8行进行循环
------------------------------------------------------------------------------------------------------------------------------------
然后经历一个中间阶段
然后继续
一直到
就结束了
二维数组内存结构
不规则二维数组
在上面中不能 int arr=new int[][3],这样会报错,这个的意思就“零行三列”
- //3.编写一个方法,返回double型二维数组,数组通过解析字符串参数获得。
- //如"1,2;3,4,5;6,7,8"
- //d[0,0]=1.0 d[0,1]=2.0 d[1,0]=3.0 ....
- package me.parser;
- public class TestString{
- public static void main(String[] args){
- //1.用字符串分解split(";")成三个字符串数组
- //2.再分解split(",")
- //声明一个二维数组用来装分解好的字符
- String s="1,2;3,4,5;6,7,8";
- //以split()方法 分解
- String[] sFirst=s.split(";");
- String[][] word=new String[sFirst.length][];
- int flag=0;
- for(int i=0;i<sFirst.length;i++){
- //打印出已经分开的
- //System.out.println(sFirst[i]);
- /*这条语句输出
- 1,2
- 3,4,5
- 6,7,8
- *///接下来在按照 ,分开他们放入一个一维数组
- String[] sSecond=sFirst[i].split(",");
- //~ System.out.println(sSecond.length);
- //~ /*输出:
- //~ 2
- //~ ---------------------------------
- //~ 3
- //~ ---------------------------------
- //~ 3
- //~ ---------------------------------
- //~ *///说明每次sSencond这个一维数组的长度不同
- 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();
- }
- /*结果:
- ---------------这是第1次循环-------------------
- ---------------这是第2次循环-------------------
- ---------------这是第3次循环-------------------
- 输出二维数组-------------------
- 1 2
- 3 4 5
- 6 7 8
- 输出二维数组-------------------
- *///
- }
- }
防止表单重复提交的几种策略
Laravel5中防止XSS跨站攻击的方法
PHP + ORACLE 远程连接数据库环境配置
iview table表格内容为数组或者对象的子元素时问题讨论
jquery中 $(xxx).each() 和 $.each()的区别,以及enter键一键登录
vue.js 强行赋值、刷新数组或者对象 方法之 $.set()
vue 组件,以及组件的复用
vue 和 jquery混合使用
JS清除空格之trim()方法
- 最新文章
-
jieba
DB2 bind on z/os
db2 bind on luw
#ifndef
SYSIBM.SYSPACKSTMT db2 存储statement的表
Asp.Net MVC Identity 2.2.1 使用技巧(二)
Asp.Net MVC Identity 2.2.1 使用技巧(一)
asp.net core项目发布网站时的选项
.net core 1.0 中的asp.net identity 基本使用(一)
.net core 1.0 中的asp.net identity 的基本使用 序言
- 热门文章
-
关于iis8.5中发布的网站无法连接数据库的解决方案。
SQL常用字段类型
MVC中使用EF的技巧集(二)——分部验证
asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(四)
asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(三)
Laravel5中使用阿里大于(鱼)发送短信验证码
[PHP]
Laravel 5.4 migrate时报错: Specified key was too long error
composer Failed to decode zlib stream 无法解码zlib流
win7 任务计划 任务映像已损坏或篡改(异常来自HRESULT:0x80041321)
Copyright © 2020-2023
润新知