Results 1 to 8 of 8
  1. #1
    BookOfEliX is offline Member
    Join Date
    Feb 2015
    Posts
    20
    Rep Power
    0

    Default pentagonal program

    I have to write a program that displays the first 100 pentagonal numbers using different methods. This is what I have so far:

    Java Code:
    public class FivePointOne{
            public static void main(String[]args){
                    System.out.println("The the pentagonal numbers are: ");
            }
            //this method will find the penagonal numbers
            public static int getPentagonalNumber(int n){
                    for(int i = 0; i < 100 ; i++){
                            if(valueOfEquation(i) % 5 == 0)
    
                    }
                    //return n;
            }
            //This method will calculate the numerator
            public static int getNumerator(int n){
                    int N = (n*((3*n)-1));
                    return N;
            }
            //This method defines the denominator
            public static int getDenominator(int n){
                    final int d = 2;
                    return d;
            }
            //This method will calcualte the equation
            public static int valueOfEquation(int n){
                    int value = getNumerator(N) / getDenominator(d) ;
                    return value;
            }
    
    }


    But when I compile it to test it out I receive the error message "Illegal start of expression," ';' expected, and "reach end of file while parsing". Can anyone explain to me what is going on and how to fix it so?
    Last edited by BookOfEliX; 02-28-2015 at 08:27 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    15

    Default Re: pentagonal program

    Pleas post the code between tags to preserve formatting. It would be easier to find such errors if you properly indent your code. And count your braces {} to make certain they are matched.

    Note: In your last two methods you pass a parameter but never use it. Why?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    BookOfEliX is offline Member
    Join Date
    Feb 2015
    Posts
    20
    Rep Power
    0

    Default Re: pentagonal program

    Hey jim, How would i go about doing that? I am new to this.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    15

    Default Re: pentagonal program

    Sorry, my tags didn't appear. Go to advance editor, highlight your code and click on the # sign.
    That will surround your code with [code][/code] tags.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    BookOfEliX is offline Member
    Join Date
    Feb 2015
    Posts
    20
    Rep Power
    0

    Default Re: pentagonal program

    like that?

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    15

    Default Re: pentagonal program

    Quote Originally Posted by BookOfEliX View Post
    like that?
    Yes. Look at your first for loop. The if statement needs work.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    Juan2114 is offline Member
    Join Date
    Feb 2015
    Posts
    5
    Rep Power
    0

    Default Re: pentagonal program

    #9990545 - Pastie

    Modified your code a little bit, but still there are some methods that you arent 'using properly' i think.

  8. #8
    BookOfEliX is offline Member
    Join Date
    Feb 2015
    Posts
    20
    Rep Power
    0

    Default Re: pentagonal program

    Hey guys I decided to start over and was able to solve it. Thanks for your help.

Similar Threads

  1. Replies: 6
    Last Post: 12-15-2013, 06:40 AM
  2. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  3. Math: pentagonal numbers
    By pullinghair in forum New To Java
    Replies: 1
    Last Post: 09-23-2011, 05:19 PM
  4. Pentagonal Number problem
    By Jason in forum New To Java
    Replies: 5
    Last Post: 09-07-2011, 06:19 AM
  5. Math: pentagonal numbers
    By Latanyar in forum New To Java
    Replies: 7
    Last Post: 10-10-2010, 03:14 PM

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
  •