arrayCount9([1, 2, 9]) → 1
arrayCount9([1, 9, 9]) → 2
arrayCount9([1, 9, 9, 3, 9]) → 3
public int arrayCount9(int[] nums) {
int count = 0;
for (int i=0; i<nums.length; i++)
{
if (nums[i] == 9) {// checks if nums have 9
count++;
}
return count;// gives num back
}
Я не знаю, как превратить это в цикл. Но я попробовал !! Также как я могу объявить его в основном методе? Любая помощь!Как я могу преобразовать массив с позиции для while
while(i<nums.length)
{
if (nums[i] == 9)
count++; // this only counts 9s
i++; // you need to add this to increase your array index, otherwise
}