Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: how do i make 'variable' + 1 a statement

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    44
    My Mood
    Mad
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default how do i make 'variable' + 1 a statement

    ok i need to make the part where is says gamelength * 1 a statement in this code


    class GCTask extends TimerTask {
      public void run() {
          gamelength + 1 ;  // this part ............<<that one right there
        System.gc();
      }
    }
     
     
     
     
     
    }
    public class timer {
      public static void main(String[] args) {
        Timer timer = new Timer();
        GCTask task = new GCTask();
        timer.schedule(task, 1000, 1000);
        int counter = 1;
        while (true) {
          try {
            Thread.sleep(500);
          } catch (InterruptedException e) {
          }
        }
      }
    Last edited by knoxy5467; June 11th, 2011 at 12:08 PM. Reason: solved


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: how do i make 'variable' + 1 a statement


  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: how do i make 'variable' + 1 a statement

    If I am understanding your replies in that other thread correctly, you can use:

    gamelength += 1

    To increase the gamelength value by 1.

    This is basically saying gamelength = gamelength + 1
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: how do i make 'variable' + 1 a statement

    as far as I can tell, there are two problems:

    1. You didn't declare gamelength either as a local variable of run(), or as an object field of GCTask.
    2. You're not re-assigning the result of the addition to gamelength. This can be done in 4 ways:

    // method 1: pre-increment
    ++gamelength;
    // method 2: post-increment
    gamelength++;
    // method 3: assignment add
    gamelength += 1;
    // method 4: regular add and assignment.
    gamelength = gamelength + 1;

  5. #5
    Member
    Join Date
    Jun 2011
    Posts
    44
    My Mood
    Mad
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: how do i make 'variable' + 1 a statement

    acually i shouldve just done

    gamelength ++

    but it's fixed now

Similar Threads

  1. [SOLVED] what is this? Variable?
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 7th, 2011, 11:32 PM
  2. If Statement
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 26th, 2010, 12:57 PM
  3. Use variable in array declaration statement
    By thedolphin13 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 24th, 2010, 03:42 PM
  4. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 07:57 PM
  5. If statement
    By Dave in forum Loops & Control Statements
    Replies: 2
    Last Post: August 27th, 2009, 10:11 AM