【数组】将给定字符串str="1,2,3!4,5,6,0!7,8,9"存入二维数组中。(使用 split(String regex) ) int[][] a
来源:互联网 发布:消防知识知多少手抄报 编辑:程序博客网 时间:2024/04/28 11:31
package com.qianfeng.day_12.homework;
import java.beans.IntrospectionException;
/**
* 10.将给定字符串str="1,2,3!4,5,6,0!7,8,9"存入二维数组中。(使用 split(String regex) ) int[][] a
*
* @author Administrator
*
*/
public class Test10 {
public static void main(String[] args) {
String str="1,2,3!4,5,6,0!7,8,9";
String[] strs1 = str.split("!"); //切分3节
int[][] a = new int[3][]; //那就确认的数组第一维长度
//1,2,3
//4,5,6,0
//7,8,9
for(int i = 0; i < strs1.length; i++){
String[] bb = strs1[i].split(","); //1 2 3
a[i] = str2int(bb);
}
for(int[] a1 : a){
for(int a2 : a1){
System.out.print(a2 + " ");
}
System.out.println();
}
}
//把String[] --> int[]
public static int[] str2int(String[] strs){
int[] aa = new int[strs.length];
for(int i = 0; i < strs.length; i++){
aa[i] = Integer.parseInt(strs[i]);
}
return aa;
}
}
import java.beans.IntrospectionException;
/**
* 10.将给定字符串str="1,2,3!4,5,6,0!7,8,9"存入二维数组中。(使用 split(String regex) ) int[][] a
*
* @author Administrator
*
*/
public class Test10 {
public static void main(String[] args) {
String str="1,2,3!4,5,6,0!7,8,9";
String[] strs1 = str.split("!"); //切分3节
int[][] a = new int[3][]; //那就确认的数组第一维长度
//1,2,3
//4,5,6,0
//7,8,9
for(int i = 0; i < strs1.length; i++){
String[] bb = strs1[i].split(","); //1 2 3
a[i] = str2int(bb);
}
for(int[] a1 : a){
for(int a2 : a1){
System.out.print(a2 + " ");
}
System.out.println();
}
}
//把String[] --> int[]
public static int[] str2int(String[] strs){
int[] aa = new int[strs.length];
for(int i = 0; i < strs.length; i++){
aa[i] = Integer.parseInt(strs[i]);
}
return aa;
}
}
0 0
- 【数组】将给定字符串str="1,2,3!4,5,6,0!7,8,9"存入二维数组中。(使用 split(String regex) ) int[][] a
- 编写函数 void fun(int a[2][3],int b[3][2]),将数组 a 的内容转置存入数组 b 中?
- Flex4中使用split将字符串String转化为数组Array
- Java 中 使用 String.split 分割 字符串 成 字符数组
- 将一个整型转换为整型数组例如Int num = 5546798;转为int [] {5,5,4,6,7,9,8}(不能转换为字符串)
- 将字符串截取到二维数组中
- 将字符串中的每一个字符存入数组中
- 从键盘输入一个字符串存入数组a中,再将数组a的内容复制到数组b中并 输出(不能调用strcpy函数)?
- 关于String.split(String regex, int limit)
- 关于String.split(String regex, int limit)
- 49.给定的字符串中找出小于97的字符存入数组中并输出
- 将json字符串转化成为一个string的二维数组
- 使用adatabase将打开的数据库名称存入数组中
- 将String数组转换成int数组
- VC中二维字符串数组使用总结()
- 二维数组中查找给定值
- C#中String str与String str=“”的区别 及 函数的参数数组。
- VC++读取文件内容并将其存入二维数组
- 【Python】无须numpy,利用map函数与zip(*)函数对数组转置
- 面试题 寻找缺失的页码
- 流程
- iOS UI 04 轨道和动画
- Java中ArrayList 元素的排序
- 【数组】将给定字符串str="1,2,3!4,5,6,0!7,8,9"存入二维数组中。(使用 split(String regex) ) int[][] a
- IOS中的Block的使用
- 关于字符串的判断为空
- 使用SDWebImage时的内存管理问题
- jQuery动画入门--顺序执行
- [Coursera]算法基础_Week3_递归_Q2
- 【openjudge】仙岛求药
- [leetcode] 264. Ugly Number II 解题报告
- hdu 5596 GTW likes gt(逆向思维)