Boolean

Discussion in 'Java' started by odie4penname@gmail.com, Mar 1, 2013.

  1. Guest

    Hello everyone,

    I'd like to make sure I have done this correct. I am using BluJ:

    Create a public boolean method named
    MynumberisOdd that takes an integer parameter named
    num and returns a boolean value indicating whether num is Odd.

    The method should check if num is odd and return true when the number is odd and false when the number is even

    Here is what I have:


    public class example

    {
    public static void main(String [] args)
    {
    int x=1;

    }

    public boolean isNumberOdd (int num)
    {
    return num%2 !=0;



    }
    }
    , Mar 1, 2013
    #1
    1. Advertising

  2. JLP Guest

    Le 01/03/2013 08:22, a écrit :
    > Hello everyone,
    >
    > I'd like to make sure I have done this correct. I am using BluJ:
    >
    > Create a public boolean method named
    > MynumberisOdd that takes an integer parameter named
    > num and returns a boolean value indicating whether num is Odd.
    >
    > The method should check if num is odd and return true when the number is odd and false when the number is even
    >
    > Here is what I have:
    >
    >
    > public class example
    >
    > {
    > public static void main(String [] args)
    > {
    > int x=1;
    >
    > }
    >
    > public boolean isNumberOdd (int num)
    > {
    > return num%2 !=0;
    >
    >
    >
    > }
    > }
    >


    in method main
    System.out.println(new example().isNumberOdd(1));

    Nota : Class names must start with a capital letter => Example
    JLP, Mar 1, 2013
    #2
    1. Advertising

  3. Guest

    On Friday, March 1, 2013 12:18:15 AM UTC-8, JLP wrote:
    > Le 01/03/2013 08:22, a écrit :
    >
    > > Hello everyone,

    >
    > >

    >
    > > I'd like to make sure I have done this correct. I am using BluJ:

    >
    > >

    >
    > > Create a public boolean method named

    >
    > > MynumberisOdd that takes an integer parameter named

    >
    > > num and returns a boolean value indicating whether num is Odd.

    >
    > >

    >
    > > The method should check if num is odd and return true when the number is odd and false when the number is even

    >
    > >

    >
    > > Here is what I have:

    >
    > >

    >
    > >

    >
    > > public class example

    >
    > >

    >
    > > {

    >
    > > public static void main(String [] args)

    >
    > > {

    >
    > > int x=1;

    >
    > >

    >
    > > }

    >
    > >

    >
    > > public boolean isNumberOdd (int num)

    >
    > > {

    >
    > > return num%2 !=0;

    >
    > >

    >
    > >

    >
    > >

    >
    > > }

    >
    > > }

    >
    > >

    >
    >
    >
    > in method main
    >
    > System.out.println(new example().isNumberOdd(1));
    >
    >
    >
    > Nota : Class names must start with a capital letter => Example


    Thanks. I didn't mention this part of the requirements:


    This method does NOT produce any output itself (it does NOT call print, println, or printf
    inside its method body—the calling code does that for the execution!).

    Is this correct? This is what I have now:

    public class Example

    {
    public static void main(String [] args)
    {
    int x=1;

    System.out.println(new Example().isNumberOdd(1));


    }

    public boolean isNumberOdd (int num)
    {
    return num%2 !=0;



    }
    }
    , Mar 1, 2013
    #3
  4. Eric Sosman Guest

    On 3/1/2013 9:42 AM, wrote:
    > On Friday, March 1, 2013 12:18:15 AM UTC-8, JLP wrote:
    >> Le 01/03/2013 08:22, a écrit :
    >>
    >>> Create a public boolean method named
    >>> MynumberisOdd [...]

    ^^^^^^^^^^^^^

    >>
    >>> public boolean isNumberOdd (int num)

    ^^^^^^^^^^^

    Actually, the name you have chosen is better than the
    one the problem statement demands. (See below.)

    >> Nota : Class names must start with a capital letter => Example


    A bit of context on this "must." The Java language does
    not require CapitalizedClassNames, nor camelCaseMethodNames,
    and a Java implementation will accept and execute code that
    uses other kinds of names. However, there are widely-followed
    conventions about how to write names for different kinds of
    things: packages, classes, interfaces, methods, and so on.
    Human readers are accustomed to these conventions and will
    find code easier to read and understand if the conventions
    are followed. Bear in mind that code in any programming
    language is written for two audiences: Computers and people.
    Of the two, people are the more important.

    > Is this correct? This is what I have now:
    >
    > public class Example
    > {
    > public static void main(String [] args)
    > {
    > int x=1;


    `x' is never used; why is it here?

    > System.out.println(new Example().isNumberOdd(1));


    Did you mean `...isNumberOdd(x)', perhaps? Also, if the
    idea is to demonstrate that the method works correctly, it
    might be a good idea to try a few other argument values: a good
    set of test cases would probably include both odd and even
    numbers, negative and positive numbers, and the special "edge
    cases" 0, Integer.MAX_VALUE, and Integer.MIN_VALUE.

    > }
    >
    > public boolean isNumberOdd (int num)
    > {
    > return num%2 !=0;
    > }
    > }


    Looks all right to me. Since the isNumberOdd() method
    relies only on the value of its parameter and not upon any
    "context" from an enclosing object, it might be slightly
    better to write it as a `static' method and call it as such
    (if you've learned about `static' yet).

    --
    Eric Sosman
    d
    Eric Sosman, Mar 1, 2013
    #4
  5. Guest

    Thanks all. Yes, the assignment is simply to show it works correct. This is my second time working with BluJ. I am just starting to learn.


    I am not sure if this part is correct:

    public static void main(String [] args)
    {
    int x=1;

    -Should it be int num=1; ?

    Here is more details of my assignment. I hope this helps in understanding in case I was vague in my prior posts:


    invoke this method for the following values for the num parameter (in the specified order)
    You can do this directly from main or from some other method / methods invoked by main.
    When the method is invoked, one of the calling methods must output the appropriate
    message.

    In other words:
    if we passed the value
    0 as an argument to num,
    it would display this message (on a line by itself):

    isNumberOdd is false for the number 0


    On Thursday, February 28, 2013 11:22:49 PM UTC-8, wrote:
    > Hello everyone,
    >
    >
    >
    > I'd like to make sure I have done this correct. I am using BluJ:
    >
    >
    >
    > Create a public boolean method named
    >
    > MynumberisOdd that takes an integer parameter named
    >
    > num and returns a boolean value indicating whether num is Odd.
    >
    >
    >
    > The method should check if num is odd and return true when the number is odd and false when the number is even
    >
    >
    >
    > Here is what I have:
    >
    >
    >
    >
    >
    > public class example
    >
    >
    >
    > {
    >
    > public static void main(String [] args)
    >
    > {
    >
    > int x=1;
    >
    >
    >
    > }
    >
    >
    >
    > public boolean isNumberOdd (int num)
    >
    > {
    >
    > return num%2 !=0;
    >
    >
    >
    >
    >
    >
    >
    > }
    >
    > }
    , Mar 1, 2013
    #5
  6. Eric Sosman Guest

    On 3/1/2013 10:50 AM, wrote:
    > Thanks all. Yes, the assignment is simply to show it works correct. This is my second time working with BluJ. I am just starting to learn.


    For future reference, comp.lang.java.programmer is (in theory)
    for questions more advanced than yours, and the answers you see
    here are likely to presuppose more knowledge of Java than a beginner
    probably has. That is, a lot of the answers will make no sense to
    you because they'll assume you have mastered Lesson Eighteen when
    you're still struggling with Lesson Three.

    There's another newsgroup, comp.lang.java.help, that is (again,
    in theory) more suitable for those who are just getting started.
    I suggest you ask questions about forthcoming assignments there
    rather than here.

    --
    Eric Sosman
    d
    Eric Sosman, Mar 1, 2013
    #6
  7. Roedy Green Guest

    On Thu, 28 Feb 2013 23:22:49 -0800 (PST),
    wrote, quoted or indirectly quoted someone who said :

    >Here is what I have:


    have you tested it?

    Your method can be static. That simplifies things.

    see http://mindprod.com/jgloss/modulus.html#EVEN
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    One thing I love about having a website, is that when I complain about
    something, I only have to do it once. It saves me endless hours of
    grumbling.
    Roedy Green, Mar 1, 2013
    #7
  8. Joerg Meier Guest

    On Fri, 01 Mar 2013 09:08:28 -0800, Roedy Green wrote:

    > On Thu, 28 Feb 2013 23:22:49 -0800 (PST),
    > wrote, quoted or indirectly quoted someone who said :
    >>Here is what I have:

    > have you tested it?


    > Your method can be static. That simplifies things.


    > see http://mindprod.com/jgloss/modulus.html#EVEN


    I clicked that, and I have to ask: what on Gods green Earth is a "circular
    squirrel cage buffer" ?

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Mar 1, 2013
    #8
  9. Lew Guest

    JLP wrote:
    > Nota : Class names must start with a capital letter


    Not "must", "should".

    --
    Lew
    Lew, Mar 1, 2013
    #9
  10. Joerg Meier Guest

    On Fri, 01 Mar 2013 19:37:30 +0000, lipska the kat wrote:

    > On 01/03/13 17:26, Joerg Meier wrote:
    >> On Fri, 01 Mar 2013 09:08:28 -0800, Roedy Green wrote:
    >>> On Thu, 28 Feb 2013 23:22:49 -0800 (PST),
    >>> wrote, quoted or indirectly quoted someone who said :
    >>>> Here is what I have:
    >>> have you tested it?


    >>> Your method can be static. That simplifies things.


    >>> see http://mindprod.com/jgloss/modulus.html#EVEN

    >> I clicked that, and I have to ask: what on Gods green Earth is a "circular
    >> squirrel cage buffer" ?

    > Apparently
    > ...


    > http://mindprod.com/jgloss/buffer.html#SQUIRREL


    > Good question though :)


    Oh, how boring, in my head it was something much more exciting. Though I do
    marvel at having a squirrel in one of those things, I only ever saw them
    for hamsters.

    The buffer described is like the old DOS keystroke/keyboard buffer, right ?

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Mar 1, 2013
    #10
  11. Arne Vajhøj Guest

    On 3/1/2013 12:26 PM, Joerg Meier wrote:
    > On Fri, 01 Mar 2013 09:08:28 -0800, Roedy Green wrote:
    >
    >> On Thu, 28 Feb 2013 23:22:49 -0800 (PST),
    >> wrote, quoted or indirectly quoted someone who said :
    >>> Here is what I have:

    >> have you tested it?

    >
    >> Your method can be static. That simplifies things.

    >
    >> see http://mindprod.com/jgloss/modulus.html#EVEN

    >
    > I clicked that, and I have to ask: what on Gods green Earth is a "circular
    > squirrel cage buffer" ?


    It is not really anything.

    It is a term Roedy has invented.

    If you Google it you will see that he is the only one using it.

    Obviously a few things could be said about using self-invented
    terms to describe something in software development.

    Arne
    Arne Vajhøj, Mar 1, 2013
    #11
  12. Arne Vajhøj Guest

    On 3/1/2013 2:37 PM, lipska the kat wrote:
    > On 01/03/13 17:26, Joerg Meier wrote:
    >> On Fri, 01 Mar 2013 09:08:28 -0800, Roedy Green wrote:
    >>
    >>> On Thu, 28 Feb 2013 23:22:49 -0800 (PST),
    >>> wrote, quoted or indirectly quoted someone who said :
    >>>> Here is what I have:
    >>> have you tested it?

    >>
    >>> Your method can be static. That simplifies things.

    >>
    >>> see http://mindprod.com/jgloss/modulus.html#EVEN

    >>
    >> I clicked that, and I have to ask: what on Gods green Earth is a
    >> "circular
    >> squirrel cage buffer" ?

    >
    > Apparently
    > ...
    >
    > http://mindprod.com/jgloss/buffer.html#SQUIRREL
    >
    > Good question though :)


    It seems to be what everybody else is calling a
    circular buffer.

    Arne
    Arne Vajhøj, Mar 1, 2013
    #12
  13. Roedy Green Guest

    On Fri, 1 Mar 2013 18:26:43 +0100, Joerg Meier <>
    wrote, quoted or indirectly quoted someone who said :

    >I clicked that, and I have to ask: what on Gods green Earth is a "circular
    >squirrel cage buffer" ?


    People who have pet squirrels give them a wheel to exercise in. Think
    of an analogous buffer where the squirrel's feet mark the point where
    the next allocation is done.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    One thing I love about having a website, is that when I complain about
    something, I only have to do it once. It saves me endless hours of
    grumbling.
    Roedy Green, Mar 2, 2013
    #13
  14. Joerg Meier Guest

    On Fri, 01 Mar 2013 17:48:03 -0800, Roedy Green wrote:

    > On Fri, 1 Mar 2013 18:26:43 +0100, Joerg Meier <>
    > wrote, quoted or indirectly quoted someone who said :
    >>I clicked that, and I have to ask: what on Gods green Earth is a "circular
    >>squirrel cage buffer" ?

    > People who have pet squirrels give them a wheel to exercise in. Think
    > of an analogous buffer where the squirrel's feet mark the point where
    > the next allocation is done.


    I made my first ASM steps playing with one of those:

    http://support.microsoft.com/kb/60140

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Mar 2, 2013
    #14
  15. JLP Guest

    Le 01/03/2013 20:21, Lew a écrit :
    > JLP wrote:
    >> Nota : Class names must start with a capital letter

    >
    > Not "must", "should".
    >

    Yes Lew. English is not my native language and i often confound must and
    should.
    JLP, Mar 4, 2013
    #15
  16. Lew Guest

    JLP wrote:
    > Lew a écrit :
    >> JLP wrote:
    >>> Nota : Class names must start with a capital letter

    >> Not "must", "should".

    >
    > Yes Lew. English is not my native language and i often confound must and
    > should.


    Native language or not, anyone in the programming world should be familiar with the
    distinction between these terms, as it is a major part of specification documentation,
    e.g., all RFCs.

    This is not a question of knowing English but of knowing technical terms.

    --
    Lew
    Lew, Mar 4, 2013
    #16
  17. Lew Guest

    Lew wrote:
    > JLP wrote:
    >> Lew a écrit :
    >>> JLP wrote:
    >>>> Nota : Class names must start with a capital letter
    >>> Not "must", "should".

    >
    >> Yes Lew. English is not my native language and i often confound must and
    >> should.

    >
    > Native language or not, anyone in the programming world should be familiar with the
    > distinction between these terms, as it is a major part of specification documentation,
    > e.g., all RFCs.
    >
    > This is not a question of knowing English but of knowing technical terms.


    To help you with this, in technical language "must" is like "il faut que". It is mandatory.

    "Should" is more like "devoir". It is an obligation, but not a necessity.

    --
    Lew
    Lew, Mar 4, 2013
    #17
  18. Lew Guest

    Lew wrote:
    > Lew wrote:
    >> JLP wrote:
    >>> Lew a écrit :
    >>>> JLP wrote:
    >>>>> Nota : Class names must start with a capital letter
    >>>> Not "must", "should".

    >>
    >>> Yes Lew. English is not my native language and i often confound must and
    > >> should.

    >
    > To help you with this, in technical language "must" is like "il faut que".. It is mandatory.
    > "Should" is more like "devoir". It is an obligation, but not a necessity.


    Okay, after checking with a friend who's from France, I discover I'm wrong."Should" is like "devrais/t". So "You SHOULD eat" is "Vous devriez manger", and "You MUST eat" is "Il vous faut manger."

    He explained that "Vous devez manger" is like "You MUST eat" also.

    I don't speak French well so I might not have it exactly right.

    --
    Lew
    Lew, Mar 4, 2013
    #18
  19. JLP Guest

    Le 05/03/2013 00:06, Lew a écrit :
    > Lew wrote:
    >> Lew wrote:
    >>> JLP wrote:
    >>>> Lew a écrit :
    >>>>> JLP wrote:
    >>>>>> Nota : Class names must start with a capital letter
    >>>>> Not "must", "should".
    >>>
    >>>> Yes Lew. English is not my native language and i often confound must and
    >>>> should.

    >>
    >> To help you with this, in technical language "must" is like "il faut que". It is mandatory.
    >> "Should" is more like "devoir". It is an obligation, but not a necessity.

    >
    > Okay, after checking with a friend who's from France, I discover I'm wrong. "Should" is like "devrais/t". So "You SHOULD eat" is "Vous devriez manger", and "You MUST eat" is "Il vous faut manger."
    >
    > He explained that "Vous devez manger" is like "You MUST eat" also.
    >
    > I don't speak French well so I might not have it exactly right.
    >

    Thanks for French learning ;-) .
    I recognize that my fault is inexcusable (must/should) in technical terms.

    must="doit" infinitive="devoir"
    should="devrait" conditional time , infinitive="devoir" also . The
    conditional time in French removes the mandatory aspect.
    JLP, Mar 5, 2013
    #19
  20. Arne Vajhøj Guest

    On 3/4/2013 2:38 PM, Lew wrote:
    > JLP wrote:
    >> Lew a écrit :
    >>> JLP wrote:
    >>>> Nota : Class names must start with a capital letter
    >>> Not "must", "should".

    >>
    >> Yes Lew. English is not my native language and i often confound must and
    >> should.

    >
    > Native language or not, anyone in the programming world should be familiar with the
    > distinction between these terms, as it is a major part of specification documentation,
    > e.g., all RFCs.
    >
    > This is not a question of knowing English but of knowing technical terms.


    Just in case:

    http://www.ietf.org/rfc/rfc2119.txt

    Arne
    Arne Vajhøj, Mar 7, 2013
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    boolean to std_logic

    valentin tihomirov, Dec 31, 2003, in forum: VHDL
    Replies:
    3
    Views:
    14,287
    Mike Treseler
    Jan 5, 2004
  2. David R Brooks

    Re: boolean to std_logic

    David R Brooks, Dec 31, 2003, in forum: VHDL
    Replies:
    0
    Views:
    2,456
    David R Brooks
    Dec 31, 2003
  3. Replies:
    19
    Views:
    1,501
  4. J Leonard
    Replies:
    4
    Views:
    12,625
    Mark Space
    Jan 19, 2008
  5. Metre Meter
    Replies:
    7
    Views:
    355
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page