我必须写程序来检查,如果给定2个数组中的所有元素都是正
如果一切积极的因素是打印
“所有的你的数组中的元素都是正”打印多行有两个for循环
这里是我的代码:
多次打印此行代码的问题!我只需要它打印一次。
public class Demo {
public static void main(String [] args){
int [][] multi = {{2,5,7,-2,-8},{3,7,4,4,5},{2,1,3,8,9},{5,4,8,2,1},{7,8,9,6,-2}};
multiArr(multi);
}
public static void multiArr(int [] [] arr){
for(int i=0; i<arr.length; i++)
for(int j=0; j<arr[0].length; j++)
if(arr[i][j]>0)
System.out.println("All the elements of your array are positive");
}
}
这里是结果在控制台:
All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive All the elements of your array are positive :
这是一个家庭作业吗?它看起来像一个。无论哪种情况,请查看http://meta.programmers.stackexchange.com/questions/6166/open-letter-to-students-with-homework-problems – such 2015-02-23 15:41:48