a problem

J

John

Chris said:
[I sent this yesterday, but it doesn't seem to be showing up on my server.
I'll try one more time. Apologies to anyone who sees it twice -- doubly so to
John if the reason is that I emailed it to him instead of posting it]

John wrote:

Personally, I don't see why your professor would restrict you in how you
can do your code, unless he/she was trying to get you to "think outside
the box".


I suspect that a large part of this particular exercise is about understanding
boolean-valued expressions, as something more general than the XXX that goes in
an if (XXX) test.

-- chris
It took me a while to get to the point where I could think "outside the
box" and realize there were other ways to accomplish what was being
asked besides using a conditional. I was actually quite impressed with
the fact that I was able to find another way without having to look too
far into it. I'm rather curious why the jdk doesn't have a method for
integers called returnParity(). It would have made the task much easier.
 
J

John

Lew said:
And someone who can't figure that out without your help needs to change
their major to toenail clipping.

Why are we spoon-feeding this homework solution to them?

- Lew
I'm not far enough into Java at this point to have been able to see the
relationship between the last bit and it's parity, but you make a good
and valid point. I guess I should change my profession from IT Support
Technician to toenail clipper :)


Seriously though... something that makes me very nervous about answering
questions like the OP's is, how far into their study of the language are
they? If they are only past conditionals, are they at the point where
they are able to use bitwise operations? I think a good idea in
situations like this, besides suggesting they make some effort first, is
to point them in a few right directions, like bitwise operations, array
indexing (like my idea) but don't tell them how to code it. At least
that way they will be working within the boundaries of what they know
about and won't be afraid of getting penalized if the instructor thinks
they have pilfered the solution.

My 2 cents FWIW.
 
J

John

Chris said:
[I sent this yesterday, but it doesn't seem to be showing up on my server.
I'll try one more time. Apologies to anyone who sees it twice -- doubly so to
John if the reason is that I emailed it to him instead of posting it]

John wrote:

Personally, I don't see why your professor would restrict you in how you
can do your code, unless he/she was trying to get you to "think outside
the box".


I suspect that a large part of this particular exercise is about understanding
boolean-valued expressions, as something more general than the XXX that goes in
an if (XXX) test.

-- chris
BTW - your reply showed up on my server. I was just wondering the
purpose for myself..
 
L

Lew

John said:
Seriously though... something that makes me very nervous about answering
questions like the OP's is, how far into their study of the language are
they? If they are only past conditionals, are they at the point where
they are able to use bitwise operations? I think a good idea in
situations like this, besides suggesting they make some effort first, is
to point them in a few right directions, like bitwise operations, array
indexing (like my idea) but don't tell them how to code it. At least
that way they will be working within the boundaries of what they know
about and won't be afraid of getting penalized if the instructor thinks
they have pilfered the solution.

Normally I would agree with you, but the OP is the one who kept demanding
then post me the solution.Mr.Beaton

and showed less than zero willingness to put in even a nanoskootch of their
own effort. For that they should be deprived of answers altogether, perhaps
even ridiculed or held as objects of contempt.

- Lew
 
L

Lew

John said:
It took me a while to get to the point where I could think "outside the
box" and realize there were other ways to accomplish what was being
asked besides using a conditional. I was actually quite impressed with
the fact that I was able to find another way without having to look too
far into it. I'm rather curious why the jdk doesn't have a method for
integers called returnParity(). It would have made the task much easier.

It has an operator, %, that obviates the need for such a method. It has
another, &, that also works.

BTW, no method should have "return" as part of its name. "get", perhaps.

if ( Integer.getParity( num ) == 1 )

is, in real life,

if ( num % 2 == 1 ) // if ( num & 1 == 1 )

One might argue in favor of the former, but not that it is necessary given the
latter. Many, myself included, would argue that the latter is actually preferable.

- Lew
 
J

John

Lew said:
It has an operator, %, that obviates the need for such a method. It has
another, &, that also works.

BTW, no method should have "return" as part of its name. "get", perhaps.

if ( Integer.getParity( num ) == 1 )

is, in real life,

if ( num % 2 == 1 ) // if ( num & 1 == 1 )

One might argue in favor of the former, but not that it is necessary
given the latter. Many, myself included, would argue that the latter is
actually preferable.

- Lew
So is there a way to test the parity of an integer using % which will
not invoke the use of a conditional such as the OP's restrictions? I
guess the real issue is the real requirements of the OP. For example,
if someone knows that by doing a %2 on an integer and having it return
0, it would be easy enough to write a statement like this
System.out.println("Parity is : " + selectedNumber % 2); But that
precludes knowledge that the recipient may NOT have. So my question to
the OP would be... when you determine if a number is odd or even, what
are you going to do with that knowledge? Are you going to use it in an
ouput, write it to a file or what? If you don't need the word "odd" or
"even" then how you determine the parity can be as simple as doing a
modulus on it and spit out the result. If you do need the words, then
you have to come up with some way of equating the result of the mod with
a word without using a conditional.
 
J

John

Lew said:
Normally I would agree with you, but the OP is the one who kept demanding



and showed less than zero willingness to put in even a nanoskootch of
their own effort. For that they should be deprived of answers
altogether, perhaps even ridiculed or held as objects of contempt.

- Lew
Now see, here's where I disagree at least in part. I don't mind giving
suggestions and hints on the direction to take, but I don't agree with
the second part of your statement. Perhaps he did do due diligence and
only came here as a last resort. We don't know. His demanding nature
may only be due to his writing style, if his first language is not
English. Furthermore, the main reason I disagree with you (respectfully
of course) is that I would not want to be "...ridiculed or held as
objects of contempt", unless it appears absolutley obvious (and in this
case I do not believe it is) that he or she is completly unwilling to
learn the correct way of doing things. Of course we may never know
because the initial request and 3 pleas for help (that's how I read
them..so sue me :) ) this person has not said anything else.
 
A

Alex Hunsley

Faton said:
First of all, you should really solve your own homework;
this is it's purpose.
Yes!

However, if the == operator is allowed, then the solution is simple
[snip soln]

[slaps head]

Nooooo! You had it the right point above, then you spoiled it by....
going and doing his homework for him!

lex
 
A

Alex Hunsley

hi,
any one of the group ,please solve my problem

This isn't the homework drop-in service. Try attempting your homework
yourself.
Hint: you can't come and get us to do your interview for you. Or your job.
"is there is any method to find given number is even
or odd without using if ,else ,for,while,switch,conditional
operators,if else ladders...."

Yes actually, there is.
 
G

Gordon Beaton

So is there a way to test the parity of an integer using % which will
not invoke the use of a conditional such as the OP's restrictions?

It's one thing to determine the parity of the number, and another to
make a decision based on that information.

For the former, none of the forbidden operations are necessary, all
that's needed is an expression. I can come up with at least one
"creative" solution for the latter, but I'm not convinced that's the
problem the OP needs to solve.

/gordon
 
B

blmblm

[I sent this yesterday, but it doesn't seem to be showing up on my server.
I'll try one more time. Apologies to anyone who sees it twice -- doubly so to
John if the reason is that I emailed it to him instead of posting it]
Personally, I don't see why your professor would restrict you in how you
can do your code, unless he/she was trying to get you to "think outside
the box".

I suspect that a large part of this particular exercise is about understanding
boolean-valued expressions, as something more general than the XXX that goes in
an if (XXX) test.

That sounds very possible. My experience teaching second-semester
programming in Java suggests that students often don't really "get"
Boolean expressions as expressions (i.e., as expressions similar to
arithmetic expressions, but evaluating to true/false rather than
to something numeric). I'm not sure how to explain this except
by example. It seems not to occur to them that the following code
(untested):

static boolean isEven(int x) {
if ((x % 2) == 0)
return true;
else
return false;
}

could be replaced by

static boolean isEven(int x) {
return ((x % 2) == 0);
}

and they seem a little uncomfortable with the second version even
when it's suggested to them. Forcing them to come up with something
like the second version -- yeah, that might have pedagogical value.
 
F

Faton Berisha

Why should the OP do that?
When they can instead..
- get people like you to do it.
- get a job at your firm and steal your code.
- get a job as your boss.

Andrew T.

I am afraid I (respectfully) disagree.
The purpose of the newsgroup is helping the ones who ask for help.
Hints are, of course, very useful for learning,
but if a poster insists that he/she needs the solution instead,
keeping with unusable posts might be perceived as cynical.
Simply ignoring the message (or indeed the entire thread)
is, I think, a better choice.
After all, this is what I quite often do myself;
at the very moment, I believe, I had some time to spare.

Faton Berisha
 
L

Lew

Faton said:
I am afraid I (respectfully) disagree.

With which statement are you disagreeing? That people who don't do their own
homework are likely to continue to rely on others' efforts throughout their
careers? That such people are dishonest? That coddling them tends to enable
their behavior? That one might have the experience of working with such a
person by enabling such behavior? That that experience would be unpleasant?
That it would be poetic justice? That you were enabling such behavior? That
you were culpable for doing so?

These assertions were gleaned from Andrew's compact message. I may have missed
a few. All are arguable and debatable.

FWIW, probably less than .2 €, I'd agree that homework laziness is bad. You
might have been enabling, but I don't know. You are not culpable if you were.
You obviously thought about what you were doing and I respect that.

For the OP and others with "homework-sounding" questions, the oft-repeated
advice for Usenet participation is "Make an effort!", and describe that effort
in the request for feedback. Show or tell the specific approach and detailed
difficulties.

Too many times people pose academic-style questions with demands for whole
solutions in terse, haughty-sounding messages - no mention of prior effort or
specific problems. Too many times, these people react in aggrieved tones to
the "do your own [home]work" response chorus, rather than shifting to more
appropriate modes. Just take the heat in good nature and provide details; all
will instantly be forgiven and the larks will sing.

So many, like Faton, are so eager to help; it behooves seekers to show respect
for that voluntary commitment.

- Lew
 
P

Proton Projects - Moin

hi,
any one of the group ,please solve my problem
"is there is any method to find given number is even
or odd without using if ,else ,for,while,switch,conditional
operators,if else ladders...."

Hi Bharath,

Hope this program will help u

public class OddEven
{
public static void main(String[] args)
{
String[] array = new String[]{"No","Yes"};
int one = 1;
int two = Integer.parseInt(args[0]);
int result = one&two;
System.out.println("Is the given number is odd, the result is "
+array[result]);
}
}

Regards
Moin
 
N

nukleus

Lew said:
Faton said:
I am afraid I (respectfully) disagree.

With which statement are you disagreeing? That people who don't do their own
homework are likely to continue to rely on others' efforts throughout their
careers? That such people are dishonest? That coddling them tends to enable
their behavior? That one might have the experience of working with such a
person by enabling such behavior? That that experience would be unpleasant?
That it would be poetic justice? That you were enabling such behavior? That
you were culpable for doing so?

These assertions were gleaned from Andrew's compact message. I may have missed
a few. All are arguable and debatable.

FWIW, probably less than .2 €, I'd agree that homework laziness is bad. You
might have been enabling, but I don't know. You are not culpable if you were.
You obviously thought about what you were doing and I respect that.

For the OP and others with "homework-sounding" questions, the oft-repeated
advice for Usenet participation is "Make an effort!", and describe that effort
in the request for feedback. Show or tell the specific approach and detailed
difficulties.

Too many times people pose academic-style questions with demands for whole
solutions in terse, haughty-sounding messages - no mention of prior effort or
specific problems. Too many times, these people react in aggrieved tones to
the "do your own [home]work" response chorus, rather than shifting to more
appropriate modes. Just take the heat in good nature and provide details; all
will instantly be forgiven and the larks will sing.

So many, like Faton, are so eager to help; it behooves seekers to show respect
for that voluntary commitment.

So, what is YOUR problem, sire,
if someone is willing to help others
for whatever reason he thinks?

You see, it is YOUR rigid mind
that has ALL sorts of prejudices,
thinking that the entire planet Earth
is to turn around its axis
according to HIS command.

What does this model remind you,
oh wisest one of all the wisest?
 
O

Oliver Wong

[On the topic of doing other people's homework for them. nukleus seems to be
addressing Lew's message in particular]
So, what is YOUR problem, sire,
if someone is willing to help others
for whatever reason he thinks?

Sometimes, a person's intentions are good, but the effects of their
actions are bad. I'm guessing Lew considers doing someone else's homework
for them to be an example of such a scenario (and I don't disagree with
this). The idea is that while you may have good intentions, by doing another
person's homework for them, you are likely causing more harm than good in
the long term. Lew (and others) are thus pointing out the problem with this
approach so that those who are truly trying to help others will realize that
doing the homework is not the best approach for helping.

- Oliver
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Oliver said:
[On the topic of doing other people's homework for them. nukleus seems to be
addressing Lew's message in particular]
So, what is YOUR problem, sire,
if someone is willing to help others
for whatever reason he thinks?

Sometimes, a person's intentions are good, but the effects of their
actions are bad. I'm guessing Lew considers doing someone else's homework
for them to be an example of such a scenario (and I don't disagree with
this). The idea is that while you may have good intentions, by doing another
person's homework for them, you are likely causing more harm than good in
the long term. Lew (and others) are thus pointing out the problem with this
approach so that those who are truly trying to help others will realize that
doing the homework is not the best approach for helping.

I don't think that argument holds water.

There were already several posts mentioning homework.

So it should be obvious from both the question and and the previous
posts that it was likely home work.

If someone knowing that decide to answer anyway, then it must
be their decision.

What people want to help with in news groups must be their
decision based on their view of the world.

I consider it inappropriate for someone to try an impose
their own answering norms on others.

Arne
 
O

Oliver Wong

Arne Vajhøj said:
Oliver said:
[On the topic of doing other people's homework for them. nukleus seems to
be addressing Lew's message in particular]
So, what is YOUR problem, sire,
if someone is willing to help others
for whatever reason he thinks?

Sometimes, a person's intentions are good, but the effects of their
actions are bad. I'm guessing Lew considers doing someone else's homework
for them to be an example of such a scenario (and I don't disagree with
this). The idea is that while you may have good intentions, by doing
another person's homework for them, you are likely causing more harm than
good in the long term. Lew (and others) are thus pointing out the problem
with this approach so that those who are truly trying to help others will
realize that doing the homework is not the best approach for helping.

I don't think that argument holds water.

There were already several posts mentioning homework.

So it should be obvious from both the question and and the previous
posts that it was likely home work.

Right, but a person can know that this post is homework, and yet not
know why it might not be a good idea to do someone else's homework. I wasn't
focusing on Lew (and others) pointing out that this is homework, but rather
on Lew (and others) pointing out why it might not be a good idea to do other
people's homework for them.
If someone knowing that decide to answer anyway, then it must
be their decision.

What people want to help with in news groups must be their
decision based on their view of the world.

I consider it inappropriate for someone to try an impose
their own answering norms on others.

I didn't see this thread having much "imposition" (is that the correct
noun form of "impose"?), but rather it's a discussion just like any other
(though slightly off topic). Instead of people saying "I think getters and
setters are good" and others saying "I think getters and setters are bad",
it's "I think doing other people's homework is acceptable" and "I think
doing other people's homework is unacceptable". It's off topic in that we're
not discussing Java, but ethics, but it wouldn't be the first time a thread
drifted off topic in CLJP.

Personally, I take a pragmatic view on the matter. I don't like to do
other people's homework for them, but I won't chide others who decide to do
that, as I don't think it'll do much good anyway: There are too many avenues
for cheating available on the internet. There are sites (e.g. RentACoder)
whose business model revolves primarily around doing other people's homework
for them.

- Oliver
 
G

Giles

With which statement are you disagreeing? That people who don't do their own
homework are likely to continue to rely on others' efforts throughout their
careers? That such people are dishonest? That coddling them tends to enable
their behavior? That one might have the experience of working with such a
person by enabling such behavior? That that experience would be unpleasant?
That it would be poetic justice? That you were enabling such behavior? That
you were culpable for doing so?
These assertions were gleaned from Andrew's compact message. I may have missed
a few. All are arguable and debatable.
FWIW, probably less than .2 €, I'd agree that homework laziness is bad. You
might have been enabling, but I don't know. You are not culpable if you were.
You obviously thought about what you were doing and I respect that.
For the OP and others with "homework-sounding" questions, the oft-repeated
advice for Usenet participation is "Make an effort!", and describe that effort
in the request for feedback. Show or tell the specific approach and detailed
difficulties.
Too many times people pose academic-style questions with demands for whole
solutions in terse, haughty-sounding messages - no mention of prior effort or
specific problems. Too many times, these people react in aggrieved tones to
the "do your own [home]work" response chorus, rather than shifting to more
appropriate modes. Just take the heat in good nature and provide details; all
will instantly be forgiven and the larks will sing.
So many, like Faton, are so eager to help; it behooves seekers to show respect
for that voluntary commitment.

So, what is YOUR problem, sire,
if someone is willing to help others
for whatever reason he thinks?

You see, it is YOUR rigid mind
that has ALL sorts of prejudices,
thinking that the entire planet Earth
is to turn around its axis
according to HIS command.

What does this model remind you,
oh wisest one of all the wisest?

Your mother's diseased ****?
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top