The question is if x >=1
then i creates the array
if not then it defaults x to 1.

Zoo has one constructor which takes an int as a parameter and uses it to instantiate the array
animals to that size, and it also sets count to zero. It should make sure the parameter is great
than or equal to 1 before using it to create the array. If invalid simply use size 1 for default.

I have this

public Zoo(int n)
{
   if(n.length >= 1)
   {
     return animals = new int[n] animal;
   else
     n = 1;
   }

   count = 0;

}

`n` is an integer (primitive type) and doesn't have a `length` property/attribute. You just need to check whether the passed in number (probably the number of animals in a Zoo) is a valid number; if not, use 1 as the default.

class Animal {}

class Zoo {
  private Animal[] animals;

  public Zoo(int n) {
    // check if `n` is invalid; if it is, reassign & make it 1
    this.animals = new Animal[n];
  }

}

Give it a shot.

EDIT: Also, you don't need a *return* statement in a constructor. You might want to read this once again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.