当前位置: 技术问答>java相关
String str = "1,1;2,3;3,5;4,8;5,11;6,15;";如何变为
来源: 互联网 发布时间:2015-10-05
本文导语: String str = "1,1;2,3;3,5;4,8;5,11;6,15;";如何变为 int[][] temp = {{1,1},{2,3},{3,5},{4,8},{5,11},{6,15}}; | import java.util.*; public class Test { public static void main(String args[]) { String str = "1,1;2,3;3,5;4,8;5,11;6,15;"; int...
String str = "1,1;2,3;3,5;4,8;5,11;6,15;";如何变为
int[][] temp = {{1,1},{2,3},{3,5},{4,8},{5,11},{6,15}};
int[][] temp = {{1,1},{2,3},{3,5},{4,8},{5,11},{6,15}};
|
import java.util.*;
public class Test
{
public static void main(String args[])
{
String str = "1,1;2,3;3,5;4,8;5,11;6,15;";
int[][] temp;// = {{1,1},{2,3},{3,5},{4,8},{5,11},{6,15}};
StringTokenizer st = new StringTokenizer(str, ",;");
temp = new int[st.countTokens()/2][2];
int i=0;
while (st.hasMoreTokens()) {
temp[i][0]=Integer.parseInt(st.nextToken());
temp[i][1]=Integer.parseInt(st.nextToken());
i++;
}
for(i=0; i
public class Test
{
public static void main(String args[])
{
String str = "1,1;2,3;3,5;4,8;5,11;6,15;";
int[][] temp;// = {{1,1},{2,3},{3,5},{4,8},{5,11},{6,15}};
StringTokenizer st = new StringTokenizer(str, ",;");
temp = new int[st.countTokens()/2][2];
int i=0;
while (st.hasMoreTokens()) {
temp[i][0]=Integer.parseInt(st.nextToken());
temp[i][1]=Integer.parseInt(st.nextToken());
i++;
}
for(i=0; i