java - Use count method and for each loop to count the number of element in the array -



java - Use count method and for each loop to count the number of element in the array -

i know how count number of element in array without each loop, have utilize each loop this. i've got far. couldn't figure out how can utilize each loop count number of elements in array. outcome should 6. appreciate help. give thanks much.

public class count{ public count(){ int a[] = {7, 8, 9, 9, 8, 7}; system.out.println(count(a)); } public int count(int count[]){ (int c : count) homecoming c; } }

public int count(int count[]) { int = 0; (int c : count) { i++; } homecoming i; }

this increment i 1 every element in array, , eventually, homecoming i, 6 (in case)

java arrays methods foreach count

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -