• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help please

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help :'(

can someone help me with this one? i have a project to be submitted tomorrow please help me

here's the problem:

write a java program that get the sum of all odd number and the product of all even numbers with in the range of 1 to 100 Using JOptionPane

hope someone could help thanks.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayvin leabres, welcome to JavaRanch.

Be more specifc when you write your post titles. "help help" will not make the people urge to help you.

What is your doubt? We are not here to write codes for you.

Post what you did, wrapped by the code tags, and we put your doubt bellow and we will help you.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayvin leabres wrote:here's the problem:
write a java program that get the sum of all odd number and the product of all even numbers with in the range of 1 to 100 Using JOptionPane
hope someone could help thanks.


Please read the NotACodeMill page. Also, this one (in fact the whole site is very good). Urgency is your problem, not ours.

Wiinston
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I read this problem, JOptionPane is only required to display the values. Ignore it for now. First get your loop (hint hint) working and printing the information to System.out.
 
Marshal
Posts: 79178
377
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you been told to use BigInteger? If not, you cannot fulfil your requirements because the product of all even numbers between 1 and 100 will overflow the limits of int and long. In fact, that calculation will return a result, both for int and long which I can easily predict, so you needn’t bother with the code .
As for odd numbers, as Rob has said you are supposed to use a loop, but there is another way to calculate that which I learnt at school.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're talking about the n * (n + 1) / 2 calculation, that's for calculating the sum of all numbers, not just odd ones. That's a little trickier. It also defies the purpose of the assignment which is clearly to use both a loop and the modulo operator.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not n * (n + 1) / 2, but m * (i + j) / 2, where m is the number of terms and i and j are the first and last terms. Agree, the idea is to use a loop, but you still must use a loop and a remainder operation for the multiplication.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote: . . . That's a little trickier. . . .

I got it right doing it in my head.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Not n * (n + 1) / 2, but m * (i + j) / 2, where m is the number of terms and i and j are the first and last terms. Agree, the idea is to use a loop, but you still must use a loop and a remainder operation for the multiplication.


Which is fine as long as the interval is constant (as it is of course in this case), so   m(2f + mi - i) / 2   (where f is the first term and i is the interval) seems slightly more correct; but well spotted.

Winston
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are all special terms of arithmetical progressions, which ought to have constant intervals between their terms.

Now, I know you (WG), Rob and I know what result that similar-to-factorial calculation multiplying even numbers from 2 to 100 will produce in a long, but do you, Jayvin leabres?
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this 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