• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

learner

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic