Results 1 to 11 of 11
Thread: Need help with array
- 05-24-2011, 04:44 PM #1
Member
- Join Date
- May 2011
- Posts
- 47
- Rep Power
- 0
Need help with array
Where am I going wrong. It's causing an error with my a,e, i, o, u. I have an array of vowels, and I need the user to input a vowel. This should send an error message if the character is not a vowel. Thanks. Here's my code.
Java Code:package vowelarray; /** * * @author Lekeisha */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class VowelArray { public VowelArray() { } /** * @param args the command line arguments */ public static void main(String[] args) { VowelArray vowelarray1 = new VowelArray(); vowelarray1.inputFromConsole(); } public void inputFromConsole() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // TODO code application logic here String[]v = {a, e, i, o, u}; System.out.println("Enter a character."); for (i=0; i< v.length; i++) { System.out.println(v[i] + " "); } try { v = br.readLine(); } catch (IOException e) { System.out.println("System found error."); } } }
- 05-24-2011, 04:49 PM #2
What kind of errors do you get? Can you compile? Can you run? What happens?
- 05-24-2011, 05:00 PM #3
Member
- Join Date
- May 2011
- Posts
- 47
- Rep Power
- 0
This is the message I get when I try to compile. I don't know where I am going wrong.
Java Code:Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: variable a location: class vowelarray.VowelArray at vowelarray.VowelArray.inputFromConsole(VowelArray.java:35) at vowelarray.VowelArray.main(VowelArray.java:25) Java Result: 1
Last edited by DarrylBurke; 05-24-2011 at 05:23 PM. Reason: Added code tags
- 05-24-2011, 05:20 PM #4
It pretty much says it all right there. At the line that says "String[]v = {a, e, i, o, u};" it can't find a variable called "a". You're trying to create an array that holds the contents of the variables called "a", "e", "i", "o", "u" and not strings. You'd need to put them into quotation-marks, i.e. "String s="a"", not "String s=a".
- 05-24-2011, 05:22 PM #5
- 05-24-2011, 05:34 PM #6
Member
- Join Date
- May 2011
- Posts
- 47
- Rep Power
- 0
Thanks for the help. I get a new message now, though. Here it is. Please help, and java is a funny language.
This is with my same code. I thought the i serves as a counter for v.
Java Code:Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: variable i location: class vowelarray.VowelArray at vowelarray.VowelArray.inputFromConsole(VowelArray.java:40) at vowelarray.VowelArray.main(VowelArray.java:25) Java Result: 1
- 05-24-2011, 05:35 PM #7
Member
- Join Date
- May 2011
- Posts
- 47
- Rep Power
- 0
New error message appeared
Thanks for the help. I get a new message now, though. Here it is. Please help, and java is a funny language.
This is with my same code. I thought the i serves as a counter for v.
Java Code:Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: variable i location: class vowelarray.VowelArray at vowelarray.VowelArray.inputFromConsole(VowelArray.java:40) at vowelarray.VowelArray.main(VowelArray.java:25) Java Result: 1
- 05-24-2011, 05:38 PM #8
Don't you think the variable "i" should have a type?
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-24-2011, 05:48 PM #9
Member
- Join Date
- May 2011
- Posts
- 47
- Rep Power
- 0
One more problem, I believe, appears with my code. I included the type with the i in the counter area, and here is the error which occurs when I try to run the application.
Java Code:Enter a character. Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types a required: java.lang.String[] e found: java.lang.String i o u at vowelarray.VowelArray.inputFromConsole(VowelArray.java:47) at vowelarray.VowelArray.main(VowelArray.java:25) Java Result: 1 BUILD SUCCESSFUL (total time: 3 seconds)
- 05-24-2011, 05:55 PM #10
Don't you think you are providing a String array where actually a String is expected? The method readLine() returns a String not a String array.
This is the 3rd time I have asked you, "Don't you think", because I really want you "to think" over this rather than bumping this thread with every error message.
Hope you will understand,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-24-2011, 05:57 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Display Array on another class after extracting from txt file and into array problem
By jonathan920 in forum NetBeansReplies: 0Last Post: 05-12-2011, 07:04 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks