This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
bobby Varghese wrote:Please...am a beginner in the field of JAVA.
Can anybody give me a hint to write an easy code?
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.
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> )
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.