伙计们,我很努力地学习过去考卷的二维数组考试。我必须写一个方法java二维数组算术
sumr static (int[][] v)
返回2D阵列由2行和v和第二行中的第一行和的项是相同的v的第一行的EG:
a = {{2,3,3}, {1,3}, {1,2}}
该方法返回二维数组
b = {{8,4,3},{2,3,3}}
我第一次尝试让我的方法返回一个二维数组,但我有表达的错误非法启动,现在我有以下的代码,但最后元素doe不打印,打印的元素全部排成一行,而不是以矩阵的方式打印......请大家帮助我,明天我的考试。
public class Sum
{
// int[][] a = {{2, 3, 3}, {1, 3}, {1, 2}};
public void sumr(int[][] v)
{
for(int rows = 0; rows < v.length; rows++){
for(int columns = 0; columns < v.length; columns++){
int result = v[rows][columns];
System.out.print(result + " ");
//return [][] result;
}
}
}
public int getCount(int[][] Array)
{
int result = 0; //temp location to store current count
for (int i = 0;i <= Array.length -1;i++){//loop around first array
//get the length of all the arrays in the first array
//and add them onto the temp variable
result += Array[i].length;
}
return result;
}
}
是什么,当你试图从该方法返回一个“二维”数组您使用的语法? – asgs 2011-05-25 13:56:02
我已经添加了作业标签(这是一个学习的东西...) – helios 2011-05-25 13:58:28
我用这个:public int [] [] sumr(int [] [] v) – learnerNo1 2011-05-25 14:00:42