Define a method countEven() that takes two dimensional array and prints the number of even numbers in the array
- برمجة جافا
- 2022-04-19
- softwareEngineer
الأجوبة
//methods benefits:
//reusability
//suitable for team work
//easier to maintain and update
public class Main
{
public static void main(String[] args) {
int a[][]={{3,5,1,7,5,2},{6,12,8,3,55,65}};
countEven(a);
}
public static void countEven(int [][]arr)
{
int count_even=0;
for(int column=0;column<arr.length;column++)
{
for(int row=0;row<arr[column].length;row++)
{
if(arr[column][row]%2==0)
count_even++;
}
}
System.out.println("the number of even numbers is: "+count_even);
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال