how to check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javaalien
    New Member
    • May 2007
    • 34

    how to check

    Kindly please anyone here helps me how to check in my program, the primitive type - int doesn't return 0 instead of 1 when it returns number between 0 - 9?

    Normally for int - it when it comes to digit 10 - it change to '0'...
    How to make sure / see my program returns correct returns decimal digit?
    Thank you in advance
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by javaalien
    Kindly please anyone here helps me how to check in my program, the primitive type - int doesn't return 0 instead of 1 when it returns number between 0 - 9?

    Normally for int - it when it comes to digit 10 - it change to '0'...
    How to make sure / see my program returns correct returns decimal digit?
    Thank you in advance
    I apologize, I don't understand your question; I reread your post several times
    but I fail to understand your question. Care to rephrase and/or elaborate?

    kind regards,

    Jos

    Comment

    • javaalien
      New Member
      • May 2007
      • 34

      #3
      Originally posted by JosAH
      I apologize, I don't understand your question; I reread your post several times
      but I fail to understand your question. Care to rephrase and/or elaborate?

      kind regards,

      Jos
      My apologize to you too.
      My lecturer's said that, check you java program and make sure that it doesn't return wrong int value (counter).
      for eg:
      Code:
      counter = 1;
      counter++
      result could be:
      1, 2, 3....., 9 and
      how to make sure the counter keeps increasing to 10, 11, 12 ant etc?

      Is that true when counter keeps increasing 1, 2, 3...9 and when it comes to 10, it comes back to count from 0, 1, 2, 3...and etc

      I don't know how to explain this, but that's what my lect's said.
      Thank you in advance

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by javaalien
        My apologize to you too.
        My lecturer's said that, check you java program and make sure that it doesn't return wrong int value (counter).
        for eg:
        Code:
        counter = 1;
        counter++
        result could be:
        1, 2, 3....., 9 and
        how to make sure the counter keeps increasing to 10, 11, 12 ant etc?

        Is that true when counter keeps increasing 1, 2, 3...9 and when it comes to 10, it comes back to count from 0, 1, 2, 3...and etc

        I don't know how to explain this, but that's what my lect's said.
        Thank you in advance
        I still don't understand your question but if you want a 'wrapping' counter as in:
        0, 1, 2, 3, ... 8, 9, 0, 1, 2, 3 ... 8, 9, 0, 1, 2, 3 etc. you can use the modulo operator:

        [code=java]
        int counter= 0; //initial value

        counter= ++counter%10; // next value over and over again ...
        [/code]

        kind regards,

        Jos

        Comment

        • javaalien
          New Member
          • May 2007
          • 34

          #5
          Originally posted by JosAH
          I still don't understand your question but if you want a 'wrapping' counter as in:
          0, 1, 2, 3, ... 8, 9, 0, 1, 2, 3 ... 8, 9, 0, 1, 2, 3 etc. you can use the modulo operator:

          [code=java]
          int counter= 0; //initial value

          counter= ++counter%10; // next value over and over again ...
          [/code]

          kind regards,

          Jos
          Sorry jos, I do not need that modulo..any way thank you for trying & really appreciate it.
          Maybe I should ask like this - (let's assume that counter is keep increasing and stops when it reach max limit (2^31-1) )

          for int type, the counter will keep increase ( initialized start from 1) and return any value between 1 and MAX_VALUE without any doubt?
          Meaning to say there's no possibility that it will count back to zero or etc.

          Comment

          • prometheuzz
            Recognized Expert New Member
            • Apr 2007
            • 197

            #6
            Originally posted by javaalien
            ...
            I don't know how to explain this, but that's what my lect's said.
            Thank you in advance

            Do you understand it yourself, or are you just repeating what your teacher told you (and you don't understand it as well)?
            Because I also have no clue what it is you're trying to do.

            Comment

            • blazedaces
              Contributor
              • May 2007
              • 284

              #7
              Alright, this is what I'm understanding in the situation:

              You have been told through a miscommunicatio n that int doesn't hold integer values greater then digits 0-9...

              You are saying that the counter you've written would print:
              0
              1
              2
              3
              4
              5
              6
              7
              8
              9
              0
              .
              .
              .

              This is not true. The counter would keep increasing. The limit on int is -127 to 128. Above that the counter would tell you an error occurred. It would not start again at 0... even if it was an unsigned int (range: 0 to 255) would not start again at 0.

              Hope this helped,
              -blazed

              Comment

              Working...