Results 1 to 3 of 3
  1. #1
    subiedude101 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default Able to compile OK, But wont run..Help

    This is for a school assignment. The exercise is:

    Write a method integerPower( base, exponent) that returns the value of base^exponent. Method integerPwer should use a for or while statement to control the calculation. Do not use any Math class methods. Incorporate this method in into an application that reads integer values for base and exponent and performs the calculation with the integerPower method. I was able to compile it OK but when I try to run it, it gives me the following error:

    Java Code:
    Exception in thread "main" java.lang.NoSuchMethodError: main

    here is my code:

    Java Code:
    public class integerPower
    {
    public void main( String[] args )
    
        {
            // create Scanner for input from command window
            Scanner input = new Scanner( System.in );
    
        // prompt for and input base and exponent
        System.out.printf( "Enter base and exponent separated by spaces: " );
    
        int base = input.nextInt(); // reads base integer
        int exponent = input.nextInt(); // reads exponent integer
         
        // determine the result
        int result = integerPower(base,exponent);
    
        // display result
    System.out.println( "Equals: " + result );
    
        } // end method main
    	
        public static int integerPower(int base, int exponent)
        {
    int product =1;
    
              for(int n = 1; n <= exponent; n++)
      product = product* base; 
     return product;
        } 
    	}

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

    Default

    Your main( ... ) method should be static.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    subiedude101 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    Awesome, thank you.

    Those little mistakes will be the death of me, I tell you what.


Similar Threads

  1. This one wont compile either.. any tips?
    By Student101 in forum New To Java
    Replies: 9
    Last Post: 11-18-2010, 05:49 AM
  2. Why wont this compile?
    By Student101 in forum New To Java
    Replies: 8
    Last Post: 11-18-2010, 05:33 AM
  3. wont validate
    By karq in forum XML
    Replies: 1
    Last Post: 10-07-2010, 05:33 PM
  4. why wont it compile
    By bje98f in forum Advanced Java
    Replies: 1
    Last Post: 04-23-2009, 10:55 PM
  5. simple problem - code wont compile
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 05:49 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
  •