Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help for writing code

 
bobby Varghese
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Looks straightforward... What have you done so far? And what are you having problems with?

Henry
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you made an attempt at this yet? Is there anything in particular you are having trouble with?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12183
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
bobby Varghese
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12183
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12183
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic