嗨,我试图返回两个数组,1作为字符串,另一个作为浮点数; 返回我在网上搜索它是令人困惑的,我是新来的oops
public String[][] loadcost(String[][] arr2, int tcount) {
int f1 = 1;
int f2 = 0;
int[] costarr = null ;
while (f2 < tcount){
arr2[f1][f2] = cost.nextLine();
costarr[f2] = Integer.parseInt (arr2[f1][f2]);
f2 = f2 + 1;
}
Arrays.sort(costarr);
return arr2 , costarr ;
Run Code Online (Sandbox Code Playgroud)
我最初的要求是对二维数组进行排序,它使用我在网上得到的代码
BBB 444 DDD 098 FF 19.01
想用第二列排序
小智 7
您需要创建一个包含两个所需类型数组的对象,然后从该方法返回该对象,因为方法只能返回一个对象.
class MyObjectName {
String[] stringArray;
Float[] floatArray;
}
public MyObjectName loadcost(String[][] arr2, int tcount) {
.....
}
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
902 次 |
| 最近记录: |