Results 1 to 11 of 11
  1. #1
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default 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.");
                
            }
            }
        
    }

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default

    What kind of errors do you get? Can you compile? Can you run? What happens?

  3. #3
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    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

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default

    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".

  5. #5
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by bamagirl31 View Post
    This is the message I get when I try to compile. I don't know where I am going wrong.
    Java Code:
    String[] v = {a, e, i, o, u};
    Don't you think String values should be written within double quotes " " ?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  6. #6
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    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

  7. #7
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default 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

  8. #8
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Don't you think the variable "i" should have a type?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  9. #9
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    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)

  10. #10
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by bamagirl31 View Post
    Java Code:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
    
      required: java.lang.String[]
    
      found:    java.lang.String
    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,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by bamagirl31 View Post
    Java Code:
            String[]v = {a, e, i, o, u};
    What are a, e, i, i and u? You're trying to initialize an arary with variables that aren't defined. With your approach you're overcomplicating matters; have a look at this:

    Java Code:
    boolean isVowel(char c) {
       return "aeiou".indexOf(c) >= 0;
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 0
    Last Post: 05-12-2011, 07:04 PM
  2. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  3. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  4. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •