Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Boolean

Reply
Thread Tools

Boolean

 
 
odie4penname@gmail.com
Guest
Posts: n/a
 
      03-01-2013
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;



}
}
 
Reply With Quote
 
 
 
 
JLP
Guest
Posts: n/a
 
      03-01-2013
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
 
Reply With Quote
 
 
 
 
odie4penname@gmail.com
Guest
Posts: n/a
 
      03-01-2013
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;



}
}
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      03-01-2013
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
 
Reply With Quote
 
odie4penname@gmail.com
Guest
Posts: n/a
 
      03-01-2013
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, odie4p...@gmail.com 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;
>
>
>
>
>
>
>
> }
>
> }

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      03-01-2013
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-01-2013
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.
 
Reply With Quote
 
Joerg Meier
Guest
Posts: n/a
 
      03-01-2013
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.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-01-2013
JLP wrote:
> Nota : Class names must start with a capital letter


Not "must", "should".

--
Lew
 
Reply With Quote
 
Joerg Meier
Guest
Posts: n/a
 
      03-01-2013
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtle difference between boolean value and boolean comparison? Metre Meter Javascript 7 08-06-2010 08:40 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
Why not use boolean all the time for synthesis? me@me.net VHDL 19 09-20-2004 12:37 PM
boolean to std_logic valentin tihomirov VHDL 3 01-05-2004 04:48 PM
Re: boolean to std_logic David R Brooks VHDL 0 12-31-2003 11:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57