Re: Program will add but cannot get it to multiply
- From: "Daniel Dyer" <dan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 20:51:42 -0000
On Tue, 31 Jan 2006 20:50:18 -0000, Daniel Dyer <dan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
int sum = 0;
for ( int number = 0; number <=100; number +=2 ) sum += number;
JOptionPane.showMessageDialog ( null, "The sum is " + sum, "Sum Odd Integerts from 1 to 100", JOptionPane.INFORMATION_MESSAGE );
Your range is 0-99, not 1-100. What happens when you multiply something by zero?
Dan.
Sorry your range is 0-100, but the point still stands. Initialise number to 1 instead of 0 and it should work.
Dan.
-- Daniel Dyer http://www.dandyer.co.uk .
- Follow-Ups:
- Re: Program will add but cannot get it to multiply
- From: shannon
- Re: Program will add but cannot get it to multiply
- References:
- Program will add but cannot get it to multiply
- From: shannon
- Re: Program will add but cannot get it to multiply
- From: Daniel Dyer
- Program will add but cannot get it to multiply
- Prev by Date: Re: Program will add but cannot get it to multiply
- Next by Date: Installation Woes (Windows)
- Previous by thread: Re: Program will add but cannot get it to multiply
- Next by thread: Re: Program will add but cannot get it to multiply
- Index(es):
Relevant Pages
|