• Post Reply Bookmark Topic Watch Topic
  • New Topic

learner  RSS feed

 
aman siddiquee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone help me out with writing a code so that I can sum up the firs 100 digitd and store the results.

i am a beginner, the question might be stupid but I appreciate your help.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aman siddiquee:
can someone help me out with writing a code so that I can sum up the firs 100 digitd and store the results...

Welcome to JavaRanch!

Sure, we'll help you out, but we won't do it for you. What have you done so far? Where are you stuck?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to start, think about how YOU would add the first 100 numbers and store results. don't think in Java, think in English, Spanish, Korean, or whatever language you are most comfortable with.

be specific. don't just say "i'd add them up and write down the result."

HOW would you add them up. how would you make sure you got all of them? where would you store the result (or any intermediary result you may have along the way)?

once you answer these, writing the Java becomes much easier.
 
Jeff Jetton
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good advice from Fred. I'd also suggest that you break the problem down into smaller problems.

For example, how would you simply print out the first 100 numbers? Don't worry about adding them up or anything at this point.

Once you get that figured out and working correctly, then work on summing them up.

Good luck!

- Jeff
 
Guru Yegnanarayanan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class addition{
public static void main(String arg[])
{
int c=0;
for(int i=1;i<101;i++)
c+=i;

system.out.println("PRINTING SUM OF 1st 100 no."+c);
}
}
[ August 30, 2006: Message edited by: Guru Yegnanarayanan ]
 
aman siddiquee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your replies and I appreciate your efforts for giving me tips to learn Java further
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guru,

As it says at the top of the forum page...
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!