Learn how to a build a cloud-first strategyRegister Now


Java Error

Posted on 2008-11-18
Medium Priority
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.in);
        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

Expert Comment

ID: 22991489
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

Accepted Solution

pratap_sms earned 2000 total points
ID: 22992251
The method signature is int getVowelCount(String s)

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 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