Solved

user-defined method

Posted on 2003-10-29
1
1,469 Views
Last Modified: 2008-03-04
I'm trying to write a program that prompts the user to input a sequence of characters and outputs the number of vowels.
I have to use the method isVowel.

and i got 2 errors:
1) public static boolean isVowel(char ch)  --> illegal start of expression
2) if (isVowel(userInput.charAt(i)) == true) --> cannot resolve symbol

here's my codes:
import java.io.*;

public class Vowel
{
      static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
      
      public static void main(String[] args)throws IOException
      {
            //declares variables
            int stringLength;
            int counter = 0;
            int i;

        String inputLine;

            System.out.println("enter a sequence of characters: ");
            System.out.flush();
            inputLine = keyboard.readLine();
            
            //evaluates the length of user's input
            stringLength = inputLine.length();

            for(i = 0; i <= (stringLength - 1); i++)
            {
                  //calls method isVowel
                  if (isVowel(userInput.charAt(i)) == true)
                  {
                        counter++;
                  }
        }

        System.out.println("The number of vowels in this sequence: " + counter);

            //creates method isVowel
            public static boolean isVowel(char ch)
            {
                  if((ch == 'a')||(ch == 'e')||(ch == 'i')||(ch == 'o')||(ch == 'u'))
                  {
                        return true;
                   }
              
                    else
                   {
                    return false;
              }
          };
      }
}

please teach me.....
0
Comment
Question by:crystalfish0318
1 Comment
 
LVL 1

Accepted Solution

by:
sre23 earned 20 total points
ID: 9647727
>> if (isVowel(userInput.charAt(i)) == true)
This should be:

if(isVowel(inputLine.charAt(i)) == true)


And you second problem is you just have a parenthesis in the wrong place.  Your first method main() doesn't have an ending parenthesis.  Here is the correct code:

import java.io.*;

public class Vowel
{
     static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
     
     public static void main(String[] args)throws IOException
     {
          //declares variables
          int stringLength;
          int counter = 0;
          int i;

        String inputLine;

          System.out.println("enter a sequence of characters: ");
          System.out.flush();
          inputLine = keyboard.readLine();
         
          //evaluates the length of user's input
          stringLength = inputLine.length();

          for(i = 0; i <= (stringLength - 1); i++)
          {
               //calls method isVowel
               if (isVowel(inputLine.charAt(i)) == true)
               {
                    counter++;
               }
        }

        System.out.println("The number of vowels in this sequence: " + counter);
    }

          //creates method isVowel
          public static boolean isVowel(char ch)
          {
               if((ch == 'a')||(ch == 'e')||(ch == 'i')||(ch == 'o')||(ch == 'u'))
               {
                    return true;
                 }
             
                  else
                 {
                  return false;
             }
         };
     
}




0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
Apps blocked by Java 9 88
jdbc error in jsp application 20 63
Eclipse Java import and method not resolved 4 49
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question