Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Returning an int to its original value?

Options
  • 24-11-2008 7:37pm
    #1
    Closed Accounts Posts: 9


    Hi. I'm new to java and I'm just wondering if someone could tell me how to return an int to its original value.

    I used int times = Console.readInt(); ,then in a loop i decreased its value until it got to zero.

    But outside this loop i want to return it to its original value.

    Any help would be warmly accepted.

    Thanks.


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    Initalise times outside of the loop and assign times to another variable?


  • Closed Accounts Posts: 194 ✭✭charlesD


    Initalise times outside of the loop and assign times to another variable?

    Yep, just don't use time and instead create a new value for the loop. For instance for a for loop you could say:


    int times = Console.readInt();

    for(int index = times; index > 0; index--)
    //Do Something...



    I didn't just do your homework did I?


  • Closed Accounts Posts: 9 mcdonagh521


    Assigning it to a different variable worked perfectly.
    Thanks a lot Creamy Goodness.

    Thanks CharlesD as well, and it wasn't homework, we were doing work earlier in the computer lab, and i couldn't figure out how to do one of the questions.
    I thought if i never found out how to do it, i would never improve.
    So thanks again.


  • Closed Accounts Posts: 194 ✭✭charlesD


    Thanks CharlesD as well, and it wasn't homework, we were doing work earlier in the computer lab, and i couldn't figure out how to do one of the questions.
    I thought if i never found out how to do it, i would never improve.
    So thanks again.

    Glad you got it working, I was mostly kidding anyway ;)


Advertisement