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 3 of 3

Thread: this method must return an int type /// + if

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default this method must return an int type /// + if

    I want to use a method, which takes for example an int and also returns an integer.
    For example, if the the given integer is strong return a, if it is notstrong return b.
    How would you write that in a Code?

    I want to use that in a more general way.
    I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
    mlong should return an int depending on the X.moth.

    at the moment my code looks like this:

    // File1:

    public class date {
    public int day;
    public int month;
    public int year;

    }


    // File 2:

    public class monthlength {

    public int mlong(date X) {

    int t;
    t = X.month;
    if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12)
    { return 31; }

    if(t == 4 || t == 6 || t == 9 || t == 11)
    {return 30;}

    }
    }


    Can plz someone help me and point out how to fix this?
    Last edited by imago23; September 7th, 2014 at 11:34 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: this method must return an int type /// + if

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    What needs fixing?

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: this method must return an int type /// + if

    What should your method return if t is 2, t < 1 or t > 12?
    Improving the world one idiot at a time!

Similar Threads

  1. return type of iterator() method
    By msnishan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2014, 08:16 AM
  2. Replies: 4
    Last Post: February 26th, 2012, 05:36 PM
  3. Replies: 3
    Last Post: October 28th, 2011, 04:42 PM
  4. Ending a method that has no return type
    By Blehs in forum Java Theory & Questions
    Replies: 3
    Last Post: August 12th, 2011, 01:56 AM
  5. error: This method must return a result of type int
    By J05HYYY in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 13th, 2011, 05:26 PM