Results 1 to 3 of 3
  1. #1
    doop is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default returning a method to main help

    public static void main(String[] args) {
    // vowel counter method
    System.out.println("input stri9ng");
    Scanner one = new Scanner(System.in);
    String input=one.next();
    int i=0;
    char a=' ';
    do{a =input.charAt(i);i++;}
    while (i<input.length());

    vowel(); //red line apears here but this is hhow i have returned a method in the past and it works



    }//end main
    public int vowel(char a){
    int vcount=0;int ccount=0;
    switch (a){
    case 'a':vcount++;
    break;
    case 'e':vcount++;
    break;
    case 'i':vcount++;
    break;
    case 'o':vcount++;
    break;
    case 'u':vcount++;
    break;
    default:ccount++;
    }

    return vcount;

    }//end class

    ################################################## ######
    error message
    ################################################## ######
    method vowel in class NewvowelCounter cannot be applied to given types;
    required: char
    found: no arguments
    reason: actual and formal argument lists differ in length
    Last edited by doop; 10-10-2012 at 12:08 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: returning a method to main help

    Your vowel( ... ) method takes one (char) parameter but you're trying to call that method without parameters. The compiler doesn't like that and told you about it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    doop is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: returning a method to main help

    ################################################## #####################
    this is the way it should be
    ################################################## #####################
    // vowel counter method
    System.out.println("input stri9ng");
    Scanner one = new Scanner(System.in);
    String input=one.next();
    int x=vowelcount(input);
    System.out.println(x);

    }//end main

    public static int vowelcount(String input){
    String methput =input;
    int i=0;
    char a=' ';
    int vcount=0;int ccount=0;
    do{ a =methput.charAt(i);i++;

    switch (a){
    case 'a':vcount++;
    break;
    case 'e':vcount++;
    break;
    case 'i':vcount++;
    break;
    case 'o':vcount++;
    break;
    case 'u':vcount++;
    break;
    default:ccount++;}}
    while (i<methput.length());

    return vcount;

Similar Threads

  1. Returning Array from a method
    By Manfizy in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2012, 12:01 PM
  2. Replies: 1
    Last Post: 12-15-2011, 04:02 AM
  3. My method keeps returning 0
    By ToolJob in forum New To Java
    Replies: 11
    Last Post: 03-27-2011, 05:22 PM
  4. Returning Value from a method
    By Mirix in forum New To Java
    Replies: 12
    Last Post: 06-01-2010, 09:48 PM
  5. returning an object from a method
    By bigj in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 12:39 PM

Posting Permissions

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