Java program that adds the numbers between 1 and 1000

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robert scherer
    New Member
    • Mar 2008
    • 10

    Java program that adds the numbers between 1 and 1000

    how do i wright a java program that adds the numbers between 1 and 1000 but skips 300 and 500 any help on this matter i would greatly appreciate

    thank you
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

      This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

      MODERATOR

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by robert scherer
        how do i wright a java program that adds the numbers between 1 and 1000 but skips 300 and 500 any help on this matter i would greatly appreciate

        thank you
        Do you know how to add those numbers *without* skipping those two numbers?
        Please show us some code because we're not doing it for you.

        kind regards,

        Jos

        Comment

        • robert scherer
          New Member
          • Mar 2008
          • 10

          #5
          // adds the numbers between 1 and 1000 excluding 300 and 500
          //

          int=sum;
          sum=1;




          this is as far as i can get i know i need a if and a while statement I know i need the while statement within my loop { }

          Comment

          • nomad
            Recognized Expert Contributor
            • Mar 2007
            • 664

            #6
            Originally posted by robert scherer
            // adds the numbers between 1 and 1000 excluding 300 and 500
            //

            int=sum;
            sum=1;




            this is as far as i can get i know i need a if and a while statement
            have you read up on counters (++), arithmetic operators and expressions?
            and if or else statements

            nomad

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              Originally posted by robert scherer
              // adds the numbers between 1 and 1000 excluding 300 and 500
              //

              int=sum;
              sum=1;




              this is as far as i can get i know i need a if and a while statement
              If that's as far as you can get, that's nowhere. You need to read your textbook or take some basic tutorials:

              This beginner Java tutorial describes fundamentals of programming in the Java programming language


              A forum isn't the right place to get help you you can't even crawl.
              Last edited by Killer42; Mar 4 '08, 10:26 PM. Reason: Activate link

              Comment

              • robert scherer
                New Member
                • Mar 2008
                • 10

                #8
                I'm Just Learning Java I Know A Few Things Like You Need ; After Certain Things Also For This Program Ill Be Using A If, And A While Statement Within My Loop , I Just Dont Know How To Get It Going

                Comment

                • robert scherer
                  New Member
                  • Mar 2008
                  • 10

                  #9
                  int sum = 0;
                  if (int i = 1; i <= 1000; ++i) {
                  sum += i;
                  while( )

                  }




                  is this better

                  Comment

                  • BigDaddyLH
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1216

                    #10
                    Originally posted by robert scherer
                    I'm Just Learning Java I Know A Few Things Like You Need ; After Certain Things Also For This Program Ill Be Using A If, And A While Statement Within My Loop , I Just Dont Know How To Get It Going
                    Then you should go carefully through the tutorial. There are examples of all that.

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by robert scherer
                      int sum = 0;
                      if (int i = 1; i <= 1000; ++i) {
                      sum += i;
                      while( )

                      }

                      is this better
                      Not really no; I think you're just guessing what your program should be without
                      knowing exactly what to do. Who gave you the idea to put that (incorrect) if-
                      statement there? An if statement takes a boolean value/expression and if it's
                      true the body of the if-statement will be executed. You actually put in an entire
                      for-clause in there. Try again and look up what for-loops can do. btw, I have no
                      idea what that while( ) thing does in there ;-)

                      kind regards,

                      Jos

                      Comment

                      • robert scherer
                        New Member
                        • Mar 2008
                        • 10

                        #12
                        Originally posted by BigDaddyLH
                        If that's as far as you can get, that's nowhere. You need to read your textbook or take some basic tutorials:

                        This beginner Java tutorial describes fundamentals of programming in the Java programming language


                        A forum isn't the right place to get help you you can't even crawl.
                        atleast I dont stutter when I SPEAK LOL

                        Comment

                        • BigDaddyLH
                          Recognized Expert Top Contributor
                          • Dec 2007
                          • 1216

                          #13
                          Originally posted by robert scherer
                          atleast I dont stutter when I SPEAK LOL
                          So true. I dictate these replies and my secretary types them in.

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            #14
                            Originally posted by BigDaddyLH
                            So true. I dictate these replies and my secretary types them in.
                            I simply whistle my replies in my good ol' audio coupler.

                            kind regards,

                            Jos

                            Comment

                            • robert scherer
                              New Member
                              • Mar 2008
                              • 10

                              #15
                              ok my friends is this closer to what i need for this program


                              //Sums all the numbers from 1 to 1000
                              //But excludes the numbers 300 and 500
                              //

                              public class Robert1
                              {
                              public static void main(String[]ARGS)
                              {
                              int sum;
                              int i;
                              for(i=1;sum=0;i <1000;i++)
                              if(300=500+i;)
                              }
                              }
                              is this right yet thanks

                              Comment

                              Working...