6 Replies Latest reply: Dec 4, 2007 11:35 AM by 807603 RSS

    Newbie Array Question - Count number of elements

      Hi all I'm new to Java and programming in general and was just wondering if anyone can tell me how to count the number of elements returned in the following code.
      int year = 0;
      int indexyear = 0;
      year = input.nextInt();
      if (year <=0)
      {pline();System.out.println("The year must be greater than 0"); AnotherGo();}     
      else if ( year >= 1)
      {pline();System.out.println("The following people were born by " + year);pline();
      while (indexyear < Peolpe.byears.length)
      if (Peolpe.byears[indexyear] <= year)
      {System.out.println(Peolpe.names[indexyear]  +  People.byears[indexyear]);}
      As you can see my code references an external class that has two arrays names and people, if I enter a 1976 as the year it returns the 3 people that were born in 1976 or earlier, however I can't figure out how to print out the number of people returned as I keep getting the total number of elements in the array as the answer.

      Any help greatly appricated.

      Edited by: Irish-Student on Dec 3, 2007 1:49 PM Put in code tags