代码形式将String str="11,22 33,44 55,66 77,88"变成int [][] a={{11,22},{33,44},{55,66}....}不能copy

2025-01-06 05:59:00
推荐回答(2个)
回答1:

String source = "11,22 33,44 55,66 77,88";
List list = new ArrayList();
String[] arr = source.split(" ");
for (int i = 0; i < arr.length; i++) {
list.add(arr[i].split(","));
}

int[][] arrs = new int[list.size()][2];

for (int i = 0; i < list.size(); i++) {
String[] temp = list.get(i);
arrs[i][0] = Integer.parseInt(temp[0]);
arrs[i][1] = Integer.parseInt(temp[1]);
}

回答2:

11 22
33 44
55 66
77 88
Press any key to continue
#include
using namespace std;
void main()
{
int i,j,k,L,nLen;
string aa="11,22 33,44 55,66 77,88";
int bb[4][2]={0};
nLen = aa.size();
char tmp[4]="\0";
for (i=0,j=0,k=0,L=0;i {
if (aa[i]!=' ' && aa[i]!=',' && aa[i]!='\0' )
{
tmp[L] = aa[i];
L++;
}
else
{
tmp[L] = '\0';
bb[j][k] = atoi(tmp);
memset(tmp,'\0',4);
L=0;
if (aa[i]==' ' || aa[i]=='\0')
{
j++;
k=0;
}
else
{
k++;
}
}
}
for (i=0;i {
for (k=0;k<2;k++)
{
printf("%d ",bb[i][k]);
}
cout< }
}

有问题请追问 满意记得采纳哦