if (count[i] == 0)
{
int [] temp0 = new int [0];
return temp0;
} Добавил на всякий случай, если получатся какие-то ошибки при создании temp2 на основе temp с длиной 0package com.javarush.task.task09.task0926;
import java.util.ArrayList;
/*
Список из массивов чисел
*/
public class Solution {
public static void main(String[] args) {
ArrayList<int[]> list = createList();
printList(list);
}
static ArrayList<Integer> temp = new ArrayList<Integer>();
public static int[] createArray (int i) {
temp.clear();
int[] count = {5, 2, 4, 7, 0};
for (int b = 0; b < count[i]; b++) {
temp.add(b);
}
int [] temp2 = new int[temp.size()];
for (int f = 0; f < temp.size(); f++)
{
temp2[f] = temp.get(f);
}
if (count[i] == 0)
{
int [] temp0 = new int [0];
return temp0;
}
else
return temp2;
}
public static ArrayList<int[]> createList() {
//напишите тут ваш код
ArrayList<int[]> list = new ArrayList<>();
for (int i = 0; i< 5; i++) {
list.add(createArray(i));
}
return list;
}
public static void printList(ArrayList<int[]> list) {
for (int[] array : list) {
for (int x : array) {
System.out.println(x);
}
}
}
}