package com.codegym.task.task06.task0614;
import java.util.ArrayList;
/*
Static cats
*/
public class Cat {
public static ArrayList<Integer> cats;
public Cat() {
}
public static void main(String[] args) {
for(int i=0;i<10;i++){
Cat cat = new Cat();
}
printCats();
}
public static void printCats() {
cats = new ArrayList<Integer>();
cats.add(cats);
}
}
how to use the ArrayList variable?
Archived
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Mohammed Amine EL AMRANI
19 December 2018, 14:23
change
with
for
you should create cat and add it to arraylist : cats.add(....);
and here should should print not add the elements 0
Roman
22 August 2018, 06:25
2. Each time a new cat (new Cat object) is created, let it be added to the variable cats. Create 10 Cat objects.
new cat is created in the main method, why you tried to add cat to the list in printCats method?
3. The printCats method should display all cats to the screen. You need to use the variable cats.
0
Yusra Ansari
22 September 2018, 17:25
How can I add to the variable cat? can you help me with that? Everything else works fine in my program ? I should add in the constructor method right?
0
Roman
24 September 2018, 05:37
show your code please
0