Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

"WHILE" Loops

Thread view: 
ericcc - 09 Oct 2007 08:54 GMT
"Use WHILE. Write an application that calculates the product of the
odd integers from 1 to 15 and then displays the result."

How would I do this?
acilelaure - 09 Oct 2007 09:07 GMT
> "Use WHILE. Write an application that calculates the product of the
> odd integers from 1 to 15 and then displays the result."
>
> How would I do this?
doing your homework ;-)

int i=3;
int e=1;
while(i<=15) {
 if( i%2 == 0 )
    e*=i;
 i++;
}
System.out.println(e);
Matt Humphrey - 09 Oct 2007 12:13 GMT
| > "Use WHILE. Write an application that calculates the product of the
| > odd integers from 1 to 15 and then displays the result."
[quoted text clipped - 10 lines]
| }
| System.out.println(e);

What an interesting, subtle answer.  Because the OP doesn't understand the
problem, he'll never find the bug in it.
Lew - 09 Oct 2007 14:37 GMT
> | > "Use WHILE. Write an application that calculates the product of the
> | > odd integers from 1 to 15 and then displays the result."
[quoted text clipped - 13 lines]
> What an interesting, subtle answer.  Because the OP doesn't understand the
> problem, he'll never find the bug in it.

But even with that lack of understanding, if they run the example they will
quickly find out that it gives the wrong answer.  They just won't know why.

Signature

Lew

Matt Humphrey - 09 Oct 2007 21:20 GMT
| > | > "Use WHILE. Write an application that calculates the product of the
| > | > odd integers from 1 to 15 and then displays the result."
[quoted text clipped - 16 lines]
| But even with that lack of understanding, if they run the example they will
| quickly find out that it gives the wrong answer.  They just won't know why.

Having taught Computer Science at a university, it's my experience that the
student will simply take the output as correct without crosschecking it.
Chronic Philharmonic - 10 Oct 2007 03:38 GMT
> | > | > "Use WHILE. Write an application that calculates the product of
> the
[quoted text clipped - 24 lines]
> the
> student will simply take the output as correct without crosschecking it.

Then they will get a grade corresponding to the effort they put into it.
Lew - 10 Oct 2007 03:47 GMT
Matt Humphrey wrote:
>> Having taught Computer Science at a university, it's my experience that
>> the
>> student will simply take the output as correct without crosschecking it.

> Then they will get a grade corresponding to the effort they put into it.

How idealistic.

Signature

Lew

Chronic Philharmonic - 10 Oct 2007 04:21 GMT
> Matt Humphrey wrote:
>>> Having taught Computer Science at a university, it's my experience that
[quoted text clipped - 4 lines]
>
> How idealistic.

Heh. Point taken, however the profs I had actually checked our work for
correctness, and graded accordingly. It has been 30 years; perhaps that is a
passé concept.
blmblm@myrealbox.com - 10 Oct 2007 10:32 GMT
> > Matt Humphrey wrote:
> >>> Having taught Computer Science at a university, it's my experience that
> >>> the
> >>> student will simply take the output as correct without crosschecking it.

My experience is similar.  Alas.  

> >> Then they will get a grade corresponding to the effort they put into it.
> >
[quoted text clipped - 3 lines]
> correctness, and graded accordingly. It has been 30 years; perhaps that is a
> passé concept.

Putting in my two cents' worth as someone who teaches undergrad
CS courses, many of them involving programming:

I can't speak for all instructors, but some of us still try to
check students' work for correctness, and -- well, I suppose it
depends on what you mean by "grade accordingly", but certainly I
deduct points if I discover [*] that a program submitted for a grade
doesn't do what it's supposed to.

[*] Usual caveats about testing apply.  I try to also at least
look at their code, but sheer volume often means I can't look
very carefully.

Signature

B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

Roedy Green - 09 Oct 2007 10:54 GMT
>"Use WHILE. Write an application that calculates the product of the
>odd integers from 1 to 15 and then displays the result."
>
>How would I do this?

see http://mindprod.com/jgloss/homework.html
http://mindprod.com/jgloss/jcheat.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

rossum - 09 Oct 2007 12:01 GMT
>"Use WHILE. Write an application that calculates the product of the
>odd integers from 1 to 15 and then displays the result."
>
>How would I do this?
Do you know what a while loop is?  Can you write one?  Were you
present when you instructor taught about while loops?  If not then you
will need to read you Java book about while loops or ask your
instructor.

Do you know what "product" means in this context?  If not then ask
your instructor for clarification.

Do you know what an "odd integer" is?  If not then consult a maths
text or ask your instructor.

Do you nkow how to display the reesult?  If not then consult your Java
book or ask your instructor.

At this point you should understand the question.  You can make your
first attempt at writing the answer.  Test your attempt and fix any
errors.  If you find you cannot fix a problem than post your code here
and we can help you.  You need to post code for two reasons: first to
show that you are willing to do the work yourself and second to let us
get a handle on how much you know so we can tailor our advice to your
level of skill.

The product of all the odd integers from 1 to 15 is 2027025, which you
will need to know when you are checking your solution.

rossum
Lew - 09 Oct 2007 14:39 GMT
> The product of all the odd integers from 1 to 15 is 2027025, which you
> will need to know when you are checking your solution.

Come on, give them credit for being able to use a calculator, at least.

>> "Use WHILE. Write an application that calculates the product of the
>> odd integers from 1 to 15 and then displays the result."

BTW, there is no such thing as "WHILE" in Java.  The assignment must have
meant something else than what people have been answering, perhaps some custom
idiom or module the professor provides?

Signature

Lew

ericcc - 09 Oct 2007 16:46 GMT
oh wow. i wasn't expecting this kind of response. all you guys are so
great, you helped me so much. i have a question though, what does
"if( i%2 != 0)" mean?
Travis James - 09 Oct 2007 17:02 GMT
> oh wow. i wasn't expecting this kind of response. all you guys are so
> great, you helped me so much. i have a question though, what does
> "if( i%2 != 0)" mean?

It means there's a mistake in the answer. Look up the word "modulus" and
it'll make sense. (If it doesn't, consider dropping the course.)
John W. Kennedy - 09 Oct 2007 22:35 GMT
>> oh wow. i wasn't expecting this kind of response. all you guys are so
>> great, you helped me so much. i have a question though, what does
>> "if( i%2 != 0)" mean?
>>
> It means there's a mistake in the answer. Look up the word "modulus" and
> it'll make sense. (If it doesn't, consider dropping the course.)

Actually, if you reread the thread closely, I think you may find that
"ericcc" is having a bit of fun with you.

Signature

John W. Kennedy
"Sweet, was Christ crucified to create this chat?"
  -- Charles Williams.  "Judgement at Chelmsford"

Andreas Leitgeb - 10 Oct 2007 16:53 GMT
> "Use WHILE. Write an application that calculates the product of the
> odd integers from 1 to 15 and then displays the result."
> How would I do this?

while (0) {}               // use while loop
long result= 2027025 + 0;  // the +0 is, so it is "calculated"
System.out.println(result);// display the result
Daniel Pitts - 10 Oct 2007 17:11 GMT
>> "Use WHILE. Write an application that calculates the product of the
>> odd integers from 1 to 15 and then displays the result."
[quoted text clipped - 3 lines]
> long result= 2027025 + 0;  // the +0 is, so it is "calculated"
> System.out.println(result);// display the result

while(0) doesn't work in Java. You need something that evaluates to a
boolean value.

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

rossum - 10 Oct 2007 17:36 GMT
>>> "Use WHILE. Write an application that calculates the product of the
>>> odd integers from 1 to 15 and then displays the result."
[quoted text clipped - 6 lines]
>while(0) doesn't work in Java. You need something that evaluates to a
>boolean value.
Shhh.  When answering homework questions you must include at least one
deliberate error so that the questioner has to actually read the code
rather than just copy it.  Andreas was right.

rossum
Daniel Pitts - 11 Oct 2007 03:11 GMT
>>>> "Use WHILE. Write an application that calculates the product of the
>>>> odd integers from 1 to 15 and then displays the result."
[quoted text clipped - 8 lines]
> deliberate error so that the questioner has to actually read the code
> rather than just copy it.  Andreas was right.

I didn't tell them how to fix the error, now did I? :-)

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Piotr Kobzda - 12 Oct 2007 10:22 GMT
>> "Use WHILE. Write an application that calculates the product of the

> long result= 2027025 + 0;  // the +0 is, so it is "calculated"

That is "calculated" by the compiler, not by an application.

piotr
Andreas Leitgeb - 12 Oct 2007 17:09 GMT
>>> "Use WHILE. Write an application that calculates the product of the
>> long result= 2027025 + 0;  // the +0 is, so it is "calculated"
> That is "calculated" by the compiler, not by an application.
hairsplitter :-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.