| Author |
Help for writing code
|
bobby Varghese
Greenhorn
Joined: Feb 12, 2009
Posts: 6
|
|
Write a program that will start with a double called sum set to zero. Add 0.1 to sum 1000 times by using a for loop.
Print the sum, and then print a statement of whether or not the sum is equal to 100.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Looks straightforward... What have you done so far? And what are you having problems with?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Paul Yule
Ranch Hand
Joined: May 12, 2008
Posts: 229
|
|
|
Have you made an attempt at this yet? Is there anything in particular you are having trouble with?
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
|
remember, we are not a code mill here. I would suggest you read over much of this to find how to get the most out of this site.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
bobby Varghese
Greenhorn
Joined: Feb 12, 2009
Posts: 6
|
|
Please...am a beginner in the field of JAVA.
Can anybody give me a hint to write an easy code?
Thank you
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
bobby Varghese wrote:Please...am a beginner in the field of JAVA.
Can anybody give me a hint to write an easy code?
Thank you
Unfortunately, it is too easy. The problem statement is already the solution, written as pseudo code. All we can say is, just start it... and post what you have. We can give you hints once you run into an issue.
Henry
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
You should find an example of a for loop in the Java Tutorials. Probably somewhere in this section. Maybe under "basics."
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
Do you know how to write anything? Have you successfully compiled a "Hello, world!" program? Have you installed java on your machine?
We can't help you, because we don't know where you are stuck.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
In a private message to me, Bobby wrote:
I know how to write Hello World.
I need a help to write the program that i told you before.
Ok, so you can write a java program, save it, compile it an run it. That means you're about 75% done with this assignment.
Generally, when writing code, you should write it in small chunks - write as little as possible, then compile-run-debug it. If there are issues, you know it most likely is in the one or two lines you just wrote.
So, here is where i'd suggest you start. Using your "Hello World" program as a template, modify it to do the first thing in your assignment:
Write a program that will start with a double called sum set to zero.
That's all you should do. Compile that much, then run it. If you take the println() line out of your original program, you probably won't see it do much, but that's ok. if it doesn't give you a compile error, and runs and exits cleanly, you're on your way. otherwise, fix whatever problems you may have, re-compile, and try again.
Once that is working, look at the next sentence:
Add 0.1 to sum 1000 times by using a for loop.
Clearly, you'll need a for-loop. Do you know how to write one? If not, doing a simple search of this site will find you some examples, as will any beginning book on java. I'll give you a word of caution... There are two kinds of for loops, that look like this:
for ( <something> ; <something> ; <something> )
and
for ( <something : ><something> )
You will want to model yours on the first kind (three things separated by semi-colons), not the second (two thing separated by a colon).
Try getting some of that done, and if you have more questions, post your code here and ask.
|
 |
 |
|
|
subject: Help for writing code
|
|
|