+ 3

Why is it throwing this error: ..\Playground\:7: error: ':' expected int foo(int[ ] array)

I am trying to run a code for array and not sure why it is throwing an error on the first line itself. I am definitely missing something, need some extra pair of eyes. https://code.sololearn.com/cM00wpp1T4Kl/?ref=app

1st Apr 2018, 4:29 PM
Shobikaj
Shobikaj - avatar
3 Answers
+ 2
šŸ‡®šŸ‡· M N is 100% correct. Your code should look like: public class LongestConsecutiveBlock { public static void main(String[] args) { int[] arr = {25, 7, 7, 14, 14, 14, 21, 3, 3, 3, 5, 12, 12, 13,13}; System.out.println(foo(arr)); } static int foo(int[] array) { int count = 1; int max = 1; for (int k = 1; k < array.length; k++) { if (array[k-1 ] <= array[k]) { count++; } else { if (count > max) { max = count; } count = 1; } } return max; } } also main should use String[] not int[]
1st Apr 2018, 4:56 PM
ChaoticDawg
ChaoticDawg - avatar
+ 4
Thanks šŸ‡®šŸ‡· M N and ChaoticDawg. it is working now...
1st Apr 2018, 5:14 PM
Shobikaj
Shobikaj - avatar
+ 2
java has not nested functions, you should move foo function outside of the main function and if you want to call it in main, it should be static
1st Apr 2018, 4:47 PM
šŸ‡®šŸ‡· M N