Results 1 to 7 of 7

Thread: Help Please....

  1. #1
    Queenzy is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default 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".... =.="

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Queenzy View Post
    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?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  4. #4
    Queenzy is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    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?

  5. #5
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    Quote Originally Posted by Queenzy View Post
    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.

  6. #6
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    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?
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Queenzy View Post
    -I just can't display properly XD
    What you mean XD?

    Quote Originally Posted by Queenzy View Post
    -The result was Sum=455650
    Is that a wrong value?

    Quote Originally Posted by Queenzy View Post
    -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?

Posting Permissions

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