Results 1 to 2 of 2
  1. #1
    kikoola is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default recursive function gives 'Class interface or enum expected' error??

    Java Code:
    import java.util.*;
        public int times(int i, int j) {
            if(j==0){
            return 0;
            } else {
            return i + times(i, j-1);}
    		}
    		
    		public class recursiveTimes{
    	
    	public static void main(String args[]){
    		
    	times multiply = new times(3,2);
    	}		}
    anyone no what I have done wrong ??

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

    Default Re: recursive function gives 'Class interface or enum expected' error??

    Methods can only be members of a class and I can see a naked method 'times( ... )' in your code; your compiler is protesting against it. (and please check your indentation).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 3
    Last Post: 01-20-2013, 08:06 PM
  2. Replies: 4
    Last Post: 12-08-2012, 10:56 AM
  3. Replies: 1
    Last Post: 10-03-2012, 09:38 PM
  4. class interface or enum expected Imports java.io.*; error
    By prathamkool in forum New To Java
    Replies: 2
    Last Post: 10-02-2011, 04:53 PM
  5. Replies: 2
    Last Post: 10-02-2010, 02:13 AM

Tags for this Thread

Posting Permissions

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