• 11-12-2008, 05:17 AM
Queenzy
I was reading a java workbook and discover this question:
-Write a program to determine the sum of the integers falling between 300 and 1000, inclusively.

Problem: I know this is very basic but it seems that I can't do it.... can anyone show me an example and teach me pls? XD

ps: "I'm only good in if and else statement".... =.="
• 11-12-2008, 05:22 AM
Eranga
Quote:

Originally Posted by Queenzy
I was reading a java workbook and discover this question:
-Write a program to determine the sum of the integers falling between 300 and 1000, inclusively.

Problem: I know this is very basic but it seems that I can't do it.... can anyone show me an example and teach me pls? XD

ps: "I'm only good in if and else statement".... =.="

Yes this is very simple. What you have tried so far?
• 11-12-2008, 05:22 AM
Fubarable
As you probably already know, you're much better off by not giving up from the very start. Try it first on your own, then if it fails show us your code. Else, how will we know what it is exactly that you don't understand?
• 11-12-2008, 05:57 AM
Queenzy
public class Lala{
public static void main (String[] args){
int sum=0;
for (int x=300;x<=1000;x++){
sum+=x;
}
System.out.println("Sum="+sum);
}
}

-I just can't display properly XD
-The result was Sum=455650
-how to make it fall instead of suming all up?
• 11-12-2008, 07:28 AM
emceenugget
Quote:

Originally Posted by Queenzy
public class Lala{
public static void main (String[] args){
int sum=0;
for (int x=300;x<=1000;x++){
sum+=x;
}
System.out.println("Sum="+sum);
}
}

-I just can't display properly XD
-The result was Sum=455650
-how to make it fall instead of suming all up?

What are you expecting as output, as opposed to what you got? Sorry, but I don't understand your last question.
• 11-12-2008, 07:48 AM
Eku
Code:

```public class Lala{ public static void main (String[] args){ int sum=0; for (int x=300;x<=1000;x++){ sum+=x; } System.out.println("Sum="+sum); } }```
***
sum += x;
is also the same as
sum = sum + x;
Thats why it will print the sum from 300 to 1000.

Now what is your question here?
• 11-12-2008, 04:46 PM
Eranga
Quote:

Originally Posted by Queenzy
-I just can't display properly XD

What you mean XD?

Quote:

Originally Posted by Queenzy
-The result was Sum=455650

Is that a wrong value?

Quote:

Originally Posted by Queenzy
-how to make it fall instead of suming all up?

What you mean by fall? I think you want to add numbers from 301 to 999, is it?