Java Error

Posted on 2008-11-18
Last Modified: 2012-05-05
Getting Error on this line
 int vowels = s.getVowelCount();
        System.out.println("The sentence had this many vowels; " + vowels);

Error states
Sentence cannot be applied to ()

Any help would greatly be appreciated.
package vowelcounttester;

import java.util.Scanner;

public class VowelCountTester


    public static void main(String[] args)


        Scanner in = new Scanner(;

        System.out.println("Enter a sentence:");

        String input = in.nextLine();


        Sentence s = new Sentence(input);


        int vowels = s.getVowelCount();

        System.out.println("The sentence had this many vowels; " + vowels);





package vowelcounttester;

public class Sentence


    public Sentence(String initText)  


       text = initText;


    public String getText()


        return text;


public int getVowelCount(String s)


  int vowelCount = 0;  


    for (int i = 0; i < s.length(); i++) {

      char c = s.charAt(i);

                if (   (c == 'A') || (c == 'a')

               || (c == 'E') ||(c == 'e') 

               || (c == 'I') || (c == 'i')

               || (c == 'O') || (c == 'o')

               || (c == 'U') || (c == 'U') ) 




return vowelCount;


private String text;


Open in new window

Question by:ca1358
    LVL 6

    Expert Comment

    The problem is that your method getVowelCount() in the class Sentence, receives one String argument
    Look at the method declaration:

    public int getVowelCount(String s)

    So you  must pass a String argument when you do this:

    int vowels = s.getVowelCount(); //here
    LVL 1

    Accepted Solution

    The method signature is int getVowelCount(String s)

    So you must call like, int vowels = s.getVowelCount("");   //note string in parenthesis

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now