Boolean

O

odie4penname

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;



}
}
 
J

JLP

Le 01/03/2013 08:22, (e-mail address removed) 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
 
O

odie4penname

Le 01/03/2013 08:22, (e-mail address removed) 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;



}
}
 
E

Eric Sosman

Le 01/03/2013 08:22, (e-mail address removed) a écrit :
Create a public boolean method named
MynumberisOdd [...]
^^^^^^^^^^^^^
^^^^^^^^^^^

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

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).
 
O

odie4penname

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
 
E

Eric Sosman

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.
 
J

Joerg Meier

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
 
A

Arne Vajhøj

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
 
R

Roedy Green

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.
 
L

Lew

JLP said:
Lew a écrit :

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.
 
L

Lew

Lew said:
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.
 
L

Lew

Lew said:
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.
 
J

JLP

Le 05/03/2013 00:06, Lew a écrit :
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top