Results 1 to 8 of 8
  1. #1
    franzwarning is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Cool How to replace and integer with another

    Hi,

    How would I display an integer, and then have it replaced with an integer that is one greater than the one before. So it is just a number counting up to lets say 4,000,000 ish.

    Thanks,
    George

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

  3. #3
    franzwarning is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default

    Java Code:
    public class Strings{
    
    public static void main(String args[]){
        double i = 0;
        int j = 1;
    
       while (i<4000000) {
           System.out.print(j);
           j++;
    }
    
    }
    }
    I just can't figure out how to have the next number replace the one before.

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

    Default

    Quote Originally Posted by franzwarning View Post
    Java Code:
    public class Strings{
    
    public static void main(String args[]){
        double i = 0;
        int j = 1;
    
       while (i<4000000) {
           System.out.print(j);
           j++;
    }
    
    }
    }
    This loop will never end as i is never changed within the loop. A for loop would be better.



    I just can't figure out how to have the next number replace the one before.
    Please elaborate. What do you mean by "to have the next number replace the one before"?

  5. #5
    franzwarning is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default

    I don't want the loop to end. I just want it to count so it will say "1" then the 1 will be replaced by a "2" which will be replaced by a "3".

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

    Default

    Quote Originally Posted by franzwarning View Post
    I don't want the loop to end. I just want it to count so it will say "1" then the 1 will be replaced by a "2" which will be replaced by a "3".
    Let's still try to clarify this. Are you saying that you want the console to display a 1, then the 1 disappears and is replaced by a 2, which disappears and is replaced by a 3? If this is the case, then forget it as consoles aren't built for this type of display and you'll be better off creating a Swing GUI to display your number.

  7. #7
    franzwarning is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default

    Alright, thats all i needed to know. Just wanted to know if it was possible to do that in a console.

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

    Default

    Quote Originally Posted by franzwarning View Post
    Alright, thats all i needed to know. Just wanted to know if it was possible to do that in a console.
    Yep. Console was the key word needed to answer this question.

    Luck.

Similar Threads

  1. How to replace int with asterisk
    By erin.ctm in forum New To Java
    Replies: 3
    Last Post: 11-12-2010, 11:13 PM
  2. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM
  3. is there anyway to replace java.IO
    By nobody58 in forum Advanced Java
    Replies: 1
    Last Post: 03-19-2010, 01:19 PM
  4. Using a replace method...
    By paul in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 04:50 AM

Posting Permissions

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