Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22650

Re: Boolean

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Boolean
Date 2013-03-01 10:25 -0500
Organization A noiseless patient Spider
Message-ID <kgqh70$jju$1@dont-email.me> (permalink)
References <38e873e0-549a-417c-b45b-9b9d52f65880@googlegroups.com> <51306447$0$1206$ba4acef3@reader.news.orange.fr> <cbb8a553-94a0-47e1-ab3c-be3f89c19c63@googlegroups.com>

Show all headers | View raw


On 3/1/2013 9:42 AM, odie4penname@gmail.com wrote:
> On Friday, March 1, 2013 12:18:15 AM UTC-8, JLP wrote:
>> Le 01/03/2013 08:22, odie4penname@gmail.com 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
esosman@comcast-dot-net.invalid

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Boolean odie4penname@gmail.com - 2013-02-28 23:22 -0800
  Re: Boolean JLP <JLP@jlp.com> - 2013-03-01 09:18 +0100
    Re: Boolean odie4penname@gmail.com - 2013-03-01 06:42 -0800
      Re: Boolean Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-01 10:25 -0500
    Re: Boolean Lew <lewbloch@gmail.com> - 2013-03-01 11:21 -0800
      Re: Boolean JLP <JLP@jlp.com> - 2013-03-04 09:12 +0100
        Re: Boolean Lew <lewbloch@gmail.com> - 2013-03-04 11:38 -0800
          Re: Boolean Lew <lewbloch@gmail.com> - 2013-03-04 11:45 -0800
            Re: Boolean Lew <lewbloch@gmail.com> - 2013-03-04 15:06 -0800
              Re: Boolean JLP <JLP@jlp.com> - 2013-03-05 11:45 +0100
          Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-06 20:19 -0500
            Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-07 08:50 +0000
              Re: Boolean Gene Wirchenko <genew@telus.net> - 2013-03-07 09:58 -0800
                Re: Boolean Lars Enderin <lars.enderin@telia.com> - 2013-03-07 19:24 +0100
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-07 19:11 +0000
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-07 19:21 +0000
                Re: Boolean Gene Wirchenko <genew@telus.net> - 2013-03-12 09:10 -0700
                Re: Boolean Patricia Shanahan <pats@acm.org> - 2013-03-12 09:54 -0700
                Re: Boolean markspace <markspace@nospam.nospam> - 2013-03-12 10:04 -0700
                Re: Boolean Lew <lewbloch@gmail.com> - 2013-03-12 12:02 -0700
              Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-07 13:50 -0500
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-07 19:00 +0000
                Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-07 14:10 -0500
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-07 19:25 +0000
              Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-07 13:52 -0500
                Re: Boolean Lars Enderin <lars.enderin@telia.com> - 2013-03-07 23:27 +0100
                Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-07 17:46 -0500
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-08 09:22 +0000
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-08 08:16 +0000
                Re: Boolean Lars Enderin <lars.enderin@telia.com> - 2013-03-08 10:30 +0100
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-08 15:00 +0000
                Re: Boolean Lars Enderin <lars.enderin@telia.com> - 2013-03-09 01:37 +0100
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-09 08:40 +0000
                Re: Boolean Lars Enderin <lars.enderin@telia.com> - 2013-03-09 09:54 +0100
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-09 09:08 +0000
                Re: Boolean Lars Enderin <lars.enderin@telia.com> - 2013-03-09 11:38 +0100
                Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-09 12:01 +0000
  Re: Boolean odie4penname@gmail.com - 2013-03-01 07:50 -0800
    Re: Boolean Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-01 11:14 -0500
  Re: Boolean Roedy Green <see_website@mindprod.com.invalid> - 2013-03-01 09:08 -0800
    Re: Boolean Joerg Meier <joergmmeier@arcor.de> - 2013-03-01 18:26 +0100
      Re: Boolean lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-01 19:37 +0000
        Re: Boolean Joerg Meier <joergmmeier@arcor.de> - 2013-03-01 21:44 +0100
        Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-01 18:34 -0500
      Re: Boolean Arne Vajhøj <arne@vajhoej.dk> - 2013-03-01 18:33 -0500
      Re: Boolean Roedy Green <see_website@mindprod.com.invalid> - 2013-03-01 17:48 -0800
        Re: Boolean Joerg Meier <joergmmeier@arcor.de> - 2013-03-02 04:03 +0100

csiph-web