Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java help

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java help

    I am getting an error message that the "isEven"method must return a result of type "int". This is after including a return statement, the error goes away if Include one more return statement. I am guessing its because of the "if-else" structure, but I want to only capture the even numbers. Can someone help me by telling me what I am doing wrong and how to fix this.

    /*
    * Printing factorials of all even numbers in a range
    */
    import acm.program.*;
    public class evenNumberTable extends ConsoleProgram{
    public void run()
    {
    int ll=readInt("Enter the lower limit of the range: ");
    int ul=readInt("Enter the upper limit of the range: ");
    for(int i=ll;i<=ul;i++)
    {
    println(factorial(isEven(i));
    }
    }
    private int isEven(int n){
    if (n % 2==0) return n;
    }
    private int factorial(int n){
    int result = 1;
    for (int i=1;i<=n;i++){
    result = result*i;
    }
    return result;
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,301
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Java help

    Thread moved from Members Introductions. Please read Announcements

Tags for this Thread