1. Member Join Date
Nov 2008
Posts
4
Rep Power
0

## Help Please....

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".... =.="  Reply With Quote

2. ##  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?  Reply With Quote

3. ## 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?  Reply With Quote

4. Member Join Date
Nov 2008
Posts
4
Rep Power
0

## 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?  Reply With Quote

5. Senior Member Join Date
Sep 2008
Posts
564
Rep Power
12

##  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.  Reply With Quote

6. Senior Member Join Date
May 2008
Location
Makati, Philippines
Posts
234
Rep Power
13

## Java 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?  Reply With Quote

7. ##  Originally Posted by Queenzy -I just can't display properly XD
What you mean XD? Originally Posted by Queenzy -The result was Sum=455650
Is that a wrong value? 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?  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•