Results 1 to 2 of 2
  1. #1
    Thousand is offline Member
    Join Date
    Dec 2009
    Posts
    5
    Rep Power
    0

    Default Writing a recursive method :S

    So I wanted to write a program which, with a recursive method tell me how many numbers there are in a given number. But it doesn't work, can anyone please help me with it?

    import java.util.*;

    public class Test27{
    public static void main(String[] args){
    nbrOfDig(1337);
    c = 0;

    static void nbrOfDig(int n){ \\ illegal start of expression ??
    c++;
    if(n > 10){
    nbrOfDig(n%10);
    }
    else{
    System.out.println(c);
    }
    }
    } \\ expected ; ??
    }

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

    Default

    You can't define a method in the body of another method. Count your curly braces.

    kind regards,

    Jos

Similar Threads

  1. recursive method problem
    By melody in forum New To Java
    Replies: 1
    Last Post: 10-29-2009, 07:15 AM
  2. Recursive method using int array, help needed
    By chupalo17 in forum New To Java
    Replies: 4
    Last Post: 09-07-2009, 11:15 PM
  3. Java Recursive method problem
    By kj2009 in forum Advanced Java
    Replies: 2
    Last Post: 02-25-2009, 03:19 PM
  4. exercise of recursive method
    By amexudo in forum New To Java
    Replies: 2
    Last Post: 03-09-2008, 05:55 PM
  5. Recursive Method
    By bluegreen7hi in forum New To Java
    Replies: 5
    Last Post: 11-29-2007, 04:45 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
  •