472,353 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Array linear search: out of bounds

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
  3.  public static void DisplayFirstAppearance (char vowel, char vowels[]) {
  4.        boolean element_found = false;
  5.         int index;
  7.         for (index = 0; element_found == false && index < NoVowels; ++index); { 
  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.     } 
After running the program i get the error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Main.DisplayFirstAppearance(Main.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 1608
11,448 Expert 8TB
I don't want to disappoint you but have a look at the String.indexOf() method.

kind regards,

Oct 14 '07 #2

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

Similar topics

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 ...
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),...
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...
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...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.