wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes searching an array....example with this problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "searching an array....example with this problem" Watch "searching an array....example with this problem" New topic
Author

searching an array....example with this problem

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76


I am not getting the right output for this....this program it is suppose to search all the persons class and if there is a match of password and username output the results.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
What output are you getting ? My guess would be an IndexOutOfBoundsException. Arrays are indexed from 0 to length -1.
Your for loops are looping from 0 to length.
Changetoand see if that helps.

I've used persons.length instead of 10, as this will allow you to change the size of your persons array without having to worry about changing the for loop.


Joanne
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10912
    
  12

PLEASE STOP POSTING NEW THREADS each time you have a new question. It gets very hard for people to follow where you are, what you're stuck on, what advice you've been given...

I'm going to close all the others. We'll make THIS one your offical thread. All follow ups should go here.

Thanks


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
The following 4 lines should be outside of the "for (int i=0 ..." loop

As it is, for each input only a single Person object is checked, instead of all of them.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: searching an array....example with this problem
 
Similar Threads
help with this program! I am stuck
Quick question about reading a Bean reading a JSF inputLabel
toString
help people for the last time
help looping through objects