Hi... M trying to declare and call a method. What am I missing here? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hi... M trying to declare and call a method. What am I missing here?

public class Program { public static void main(String[] args) { int[]arr={2,4,6}; int total =0; int result = getTotal (arr); for (int i=0;i<arr.length;i++){ total = (total += arr[i]); if (arr [i]%2==0) { if (total ==12){ System.out.println ("1") ; } else System.out.println ("0"); } } } }

1st Mar 2017, 5:22 AM
Ricardo Chitagu
Ricardo Chitagu - avatar
1 Answer
+ 1
THIS IS THE CODE! ! public class Program { public static void main(String[] args) { int[]arr={2,4,6}; int total =0; int result = getTotal (arr); for (int i=0;i<arr.length;i++){ total = (total += arr[i]); if (arr [i]%2==0) { if (total ==12){ System.out.println ("1") ; } else System.out.println ("0"); } } } } public static int getTotal(int [] a){ int result; for (int i=0;i<a.length;i++){ total = (total += a[i]); if (a[i]%2==0) { if (total ==12){ result =1 ; } else result =0; return result ; } } } //*nestedLoop
1st Mar 2017, 5:42 AM
Ricardo Chitagu
Ricardo Chitagu - avatar