473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array linear search: out of bounds

62 New Member
HI i have a method that performs a linear search to find a given vowel. The vowel parameter is a given vowel, while vowel[] is the array with all the vowels.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  public static void DisplayFirstAppearance (char vowel, char vowels[]) {
  4.        boolean element_found = false;
  5.         int index;
  6.  
  7.         for (index = 0; element_found == false && index < NoVowels; ++index); { 
  8.  
  9.            if (vowels[index] == vowel)  { // Error Here
  10.                    element_found = true; 
  11.                     }
  12.         if (element_found) {
  13.             System.out.println("The vowel: " + vowel); 
  14.             System.out.println("First appears: " + vowels[index]); 
  15.         } 
  16.         else 
  17.             System.out.print(+ vowel); 
  18.            System.out.println(" Vowel not found");
  19.     } 
  20.  
After running the program i get the error:
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 3
at Main.DisplayFir stAppearance(Ma in.java:78) --> Line 7
3 being the number of values in the array.
Anyone know how to ovr come this i noe its somthing to do with the value not being with range or somthing.
Oct 14 '07 #1
1 1666
JosAH
11,448 Recognized Expert MVP
I don't want to disappoint you but have a look at the String.indexOf( ) method.

kind regards,

Jos
Oct 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
6784
by: MIA | last post by:
Hi, I have an nxn array in which in each row is consisting of +ve and -ve numbers, such that -ve number comes before +ve numbers. e.g. -45 | -9 | -3 | 2 =================== -5 | -9 | 21 | 12 =================== -4 | 19 | 18 | 5 ===================
8
5126
by: Al | last post by:
I'd like to declare (in a Matrix class) a two-dimentional array with user-defined coordinates. The constructor is: Matrix(int c, int l): col(c), lin(l), a(new float) {} the compiler says 'lin' should be a constant, but I want it to be defined from the user, so what should I do? and how must 'a' be declared?? help me please
9
3132
by: Rick | last post by:
I have a large list of objects where each object has a unique (non-overlapping) date range. The list is sorted chronologically. What is the most efficient way to search this list for a single object that spans a specified date?
26
2560
by: mike-yue | last post by:
The topic comes from a question: Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array? 1Quicksort 2Linear Search 3Bubble Sort The answer is 2Linear Search
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.