Re: Program will add but cannot get it to multiply



On Tue, 31 Jan 2006 20:38:22 -0000, shannon <shannondingle@xxxxxxxxxxxxx> wrote:

Hi,
Just started Java and want to multiply odd numbers between 1 and 100.
However, at the moment i can only get them to add. I tried replacing
the + sign with the * multiplication sign but to no avail. Any
suggestions?


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.

--
Daniel Dyer
http://www.dandyer.co.uk
.



Relevant Pages