Increase number with character in Java












2















I have a problem with increasing number and character combinations.
What I want is increase from
001 to ZZZ




Example: 001, 002,..., 999, 00A,..., 00Z, 0AA,..., ZZZ




My code look like this:



int numberA = 1000;
int numberB = 1024;
int numberC = 1025;

/*
* Some formulae here
*/

System.out.println(numberA);
//Result: 00A
System.out.println(numberB);
//Result: 00Z
System.out.println(numberC);
//Result: 0A0


Are there any fomulae to solve this problem?










share|improve this question

























  • based on what do you want to switch to characters? would the numbers be always 3-digit? why would you want to do it (curious)?

    – Naman
    Nov 23 '18 at 12:31













  • Number is auto increase from 1 -> 18576 (001 -> ZZZ). Yes. Those output always have 3 digits. I have a school project that need to store lots of items in the warehouse, each item must have different "code" within one day. My format is yymmdd-XXX with XXX is the number above. I want to extend as much as possible the range of those number.

    – Thiện
    Nov 23 '18 at 12:41











  • Please check this stackoverflow.com/questions/5091355/increase-string-value

    – Deedar Ali Brohi
    Nov 23 '18 at 12:43











  • Do check this out stackoverflow.com/questions/28981669/…

    – Ojasvi Bhargava
    Nov 23 '18 at 12:46











  • Thanks! I'll check it out

    – Thiện
    Nov 23 '18 at 12:52
















2















I have a problem with increasing number and character combinations.
What I want is increase from
001 to ZZZ




Example: 001, 002,..., 999, 00A,..., 00Z, 0AA,..., ZZZ




My code look like this:



int numberA = 1000;
int numberB = 1024;
int numberC = 1025;

/*
* Some formulae here
*/

System.out.println(numberA);
//Result: 00A
System.out.println(numberB);
//Result: 00Z
System.out.println(numberC);
//Result: 0A0


Are there any fomulae to solve this problem?










share|improve this question

























  • based on what do you want to switch to characters? would the numbers be always 3-digit? why would you want to do it (curious)?

    – Naman
    Nov 23 '18 at 12:31













  • Number is auto increase from 1 -> 18576 (001 -> ZZZ). Yes. Those output always have 3 digits. I have a school project that need to store lots of items in the warehouse, each item must have different "code" within one day. My format is yymmdd-XXX with XXX is the number above. I want to extend as much as possible the range of those number.

    – Thiện
    Nov 23 '18 at 12:41











  • Please check this stackoverflow.com/questions/5091355/increase-string-value

    – Deedar Ali Brohi
    Nov 23 '18 at 12:43











  • Do check this out stackoverflow.com/questions/28981669/…

    – Ojasvi Bhargava
    Nov 23 '18 at 12:46











  • Thanks! I'll check it out

    – Thiện
    Nov 23 '18 at 12:52














2












2








2


2






I have a problem with increasing number and character combinations.
What I want is increase from
001 to ZZZ




Example: 001, 002,..., 999, 00A,..., 00Z, 0AA,..., ZZZ




My code look like this:



int numberA = 1000;
int numberB = 1024;
int numberC = 1025;

/*
* Some formulae here
*/

System.out.println(numberA);
//Result: 00A
System.out.println(numberB);
//Result: 00Z
System.out.println(numberC);
//Result: 0A0


Are there any fomulae to solve this problem?










share|improve this question
















I have a problem with increasing number and character combinations.
What I want is increase from
001 to ZZZ




Example: 001, 002,..., 999, 00A,..., 00Z, 0AA,..., ZZZ




My code look like this:



int numberA = 1000;
int numberB = 1024;
int numberC = 1025;

/*
* Some formulae here
*/

System.out.println(numberA);
//Result: 00A
System.out.println(numberB);
//Result: 00Z
System.out.println(numberC);
//Result: 0A0


Are there any fomulae to solve this problem?







java java-8






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 12:36









deHaar

2,66961729




2,66961729










asked Nov 23 '18 at 12:28









ThiệnThiện

285




285













  • based on what do you want to switch to characters? would the numbers be always 3-digit? why would you want to do it (curious)?

    – Naman
    Nov 23 '18 at 12:31













  • Number is auto increase from 1 -> 18576 (001 -> ZZZ). Yes. Those output always have 3 digits. I have a school project that need to store lots of items in the warehouse, each item must have different "code" within one day. My format is yymmdd-XXX with XXX is the number above. I want to extend as much as possible the range of those number.

    – Thiện
    Nov 23 '18 at 12:41











  • Please check this stackoverflow.com/questions/5091355/increase-string-value

    – Deedar Ali Brohi
    Nov 23 '18 at 12:43











  • Do check this out stackoverflow.com/questions/28981669/…

    – Ojasvi Bhargava
    Nov 23 '18 at 12:46











  • Thanks! I'll check it out

    – Thiện
    Nov 23 '18 at 12:52



















  • based on what do you want to switch to characters? would the numbers be always 3-digit? why would you want to do it (curious)?

    – Naman
    Nov 23 '18 at 12:31













  • Number is auto increase from 1 -> 18576 (001 -> ZZZ). Yes. Those output always have 3 digits. I have a school project that need to store lots of items in the warehouse, each item must have different "code" within one day. My format is yymmdd-XXX with XXX is the number above. I want to extend as much as possible the range of those number.

    – Thiện
    Nov 23 '18 at 12:41











  • Please check this stackoverflow.com/questions/5091355/increase-string-value

    – Deedar Ali Brohi
    Nov 23 '18 at 12:43











  • Do check this out stackoverflow.com/questions/28981669/…

    – Ojasvi Bhargava
    Nov 23 '18 at 12:46











  • Thanks! I'll check it out

    – Thiện
    Nov 23 '18 at 12:52

















based on what do you want to switch to characters? would the numbers be always 3-digit? why would you want to do it (curious)?

– Naman
Nov 23 '18 at 12:31







based on what do you want to switch to characters? would the numbers be always 3-digit? why would you want to do it (curious)?

– Naman
Nov 23 '18 at 12:31















Number is auto increase from 1 -> 18576 (001 -> ZZZ). Yes. Those output always have 3 digits. I have a school project that need to store lots of items in the warehouse, each item must have different "code" within one day. My format is yymmdd-XXX with XXX is the number above. I want to extend as much as possible the range of those number.

– Thiện
Nov 23 '18 at 12:41





Number is auto increase from 1 -> 18576 (001 -> ZZZ). Yes. Those output always have 3 digits. I have a school project that need to store lots of items in the warehouse, each item must have different "code" within one day. My format is yymmdd-XXX with XXX is the number above. I want to extend as much as possible the range of those number.

– Thiện
Nov 23 '18 at 12:41













Please check this stackoverflow.com/questions/5091355/increase-string-value

– Deedar Ali Brohi
Nov 23 '18 at 12:43





Please check this stackoverflow.com/questions/5091355/increase-string-value

– Deedar Ali Brohi
Nov 23 '18 at 12:43













Do check this out stackoverflow.com/questions/28981669/…

– Ojasvi Bhargava
Nov 23 '18 at 12:46





Do check this out stackoverflow.com/questions/28981669/…

– Ojasvi Bhargava
Nov 23 '18 at 12:46













Thanks! I'll check it out

– Thiện
Nov 23 '18 at 12:52





Thanks! I'll check it out

– Thiện
Nov 23 '18 at 12:52












3 Answers
3






active

oldest

votes


















5














Maybe the following will help you get started ;-)



final Integer radix = 36; // that's 0-9 A-Z
final Double limit = Math.pow(radix.doubleValue(), 3.0 /* max number of 'chars' */);
Stream.iterate(0, i -> i+1)
.map(i -> Integer.toString(i, radix))
.map(s -> String.format("000%S", s)
.substring(s.length())) // leading 0, uppercase
.limit(limit.longValue())
.forEach(System.out::println);


Or simply:



String radix36 = Integer.toString(yourIntThatYouCanIncrement, 36);


Of course if you require the 00#-format (leading zeros and uppercase) you need to apply that functions too. Holgers comment already contains a short variant of it to combine uppercase/leading zeros:



String formatted = String.format("000%S", radix36)
.substring(radix36.length());





share|improve this answer


























  • Thank you! I'll check it out

    – Thiện
    Nov 23 '18 at 12:54



















3














You can format your number as a base-36 number (you want to use 36 different digits: 0 - 9 = 10 digits + A - Z = 26 digits).



To get it exactly in the format you want (upper-case, with leading zeroes):



String s = Integer.toString(numberA, 36).toUpperCase();
String result = String.format("%3s", s).replace(' ', '0');





share|improve this answer



















  • 1





    Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

    – Holger
    Nov 23 '18 at 13:07





















1














Here is code that will print 001 to zzz sequence.



public static void main(String args){
String result="";
int i=0;
while(!result.equals("ZZZ")){
String s = Integer.toString(i, 36).toUpperCase();
result = String.format("%3s", s).replace(' ', '0');
System.out.println("t "+result);
i++;
}
}





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446748%2fincrease-number-with-character-in-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    Maybe the following will help you get started ;-)



    final Integer radix = 36; // that's 0-9 A-Z
    final Double limit = Math.pow(radix.doubleValue(), 3.0 /* max number of 'chars' */);
    Stream.iterate(0, i -> i+1)
    .map(i -> Integer.toString(i, radix))
    .map(s -> String.format("000%S", s)
    .substring(s.length())) // leading 0, uppercase
    .limit(limit.longValue())
    .forEach(System.out::println);


    Or simply:



    String radix36 = Integer.toString(yourIntThatYouCanIncrement, 36);


    Of course if you require the 00#-format (leading zeros and uppercase) you need to apply that functions too. Holgers comment already contains a short variant of it to combine uppercase/leading zeros:



    String formatted = String.format("000%S", radix36)
    .substring(radix36.length());





    share|improve this answer


























    • Thank you! I'll check it out

      – Thiện
      Nov 23 '18 at 12:54
















    5














    Maybe the following will help you get started ;-)



    final Integer radix = 36; // that's 0-9 A-Z
    final Double limit = Math.pow(radix.doubleValue(), 3.0 /* max number of 'chars' */);
    Stream.iterate(0, i -> i+1)
    .map(i -> Integer.toString(i, radix))
    .map(s -> String.format("000%S", s)
    .substring(s.length())) // leading 0, uppercase
    .limit(limit.longValue())
    .forEach(System.out::println);


    Or simply:



    String radix36 = Integer.toString(yourIntThatYouCanIncrement, 36);


    Of course if you require the 00#-format (leading zeros and uppercase) you need to apply that functions too. Holgers comment already contains a short variant of it to combine uppercase/leading zeros:



    String formatted = String.format("000%S", radix36)
    .substring(radix36.length());





    share|improve this answer


























    • Thank you! I'll check it out

      – Thiện
      Nov 23 '18 at 12:54














    5












    5








    5







    Maybe the following will help you get started ;-)



    final Integer radix = 36; // that's 0-9 A-Z
    final Double limit = Math.pow(radix.doubleValue(), 3.0 /* max number of 'chars' */);
    Stream.iterate(0, i -> i+1)
    .map(i -> Integer.toString(i, radix))
    .map(s -> String.format("000%S", s)
    .substring(s.length())) // leading 0, uppercase
    .limit(limit.longValue())
    .forEach(System.out::println);


    Or simply:



    String radix36 = Integer.toString(yourIntThatYouCanIncrement, 36);


    Of course if you require the 00#-format (leading zeros and uppercase) you need to apply that functions too. Holgers comment already contains a short variant of it to combine uppercase/leading zeros:



    String formatted = String.format("000%S", radix36)
    .substring(radix36.length());





    share|improve this answer















    Maybe the following will help you get started ;-)



    final Integer radix = 36; // that's 0-9 A-Z
    final Double limit = Math.pow(radix.doubleValue(), 3.0 /* max number of 'chars' */);
    Stream.iterate(0, i -> i+1)
    .map(i -> Integer.toString(i, radix))
    .map(s -> String.format("000%S", s)
    .substring(s.length())) // leading 0, uppercase
    .limit(limit.longValue())
    .forEach(System.out::println);


    Or simply:



    String radix36 = Integer.toString(yourIntThatYouCanIncrement, 36);


    Of course if you require the 00#-format (leading zeros and uppercase) you need to apply that functions too. Holgers comment already contains a short variant of it to combine uppercase/leading zeros:



    String formatted = String.format("000%S", radix36)
    .substring(radix36.length());






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 23 '18 at 13:11

























    answered Nov 23 '18 at 12:49









    RolandRoland

    10.5k11442




    10.5k11442













    • Thank you! I'll check it out

      – Thiện
      Nov 23 '18 at 12:54



















    • Thank you! I'll check it out

      – Thiện
      Nov 23 '18 at 12:54

















    Thank you! I'll check it out

    – Thiện
    Nov 23 '18 at 12:54





    Thank you! I'll check it out

    – Thiện
    Nov 23 '18 at 12:54













    3














    You can format your number as a base-36 number (you want to use 36 different digits: 0 - 9 = 10 digits + A - Z = 26 digits).



    To get it exactly in the format you want (upper-case, with leading zeroes):



    String s = Integer.toString(numberA, 36).toUpperCase();
    String result = String.format("%3s", s).replace(' ', '0');





    share|improve this answer



















    • 1





      Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

      – Holger
      Nov 23 '18 at 13:07


















    3














    You can format your number as a base-36 number (you want to use 36 different digits: 0 - 9 = 10 digits + A - Z = 26 digits).



    To get it exactly in the format you want (upper-case, with leading zeroes):



    String s = Integer.toString(numberA, 36).toUpperCase();
    String result = String.format("%3s", s).replace(' ', '0');





    share|improve this answer



















    • 1





      Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

      – Holger
      Nov 23 '18 at 13:07
















    3












    3








    3







    You can format your number as a base-36 number (you want to use 36 different digits: 0 - 9 = 10 digits + A - Z = 26 digits).



    To get it exactly in the format you want (upper-case, with leading zeroes):



    String s = Integer.toString(numberA, 36).toUpperCase();
    String result = String.format("%3s", s).replace(' ', '0');





    share|improve this answer













    You can format your number as a base-36 number (you want to use 36 different digits: 0 - 9 = 10 digits + A - Z = 26 digits).



    To get it exactly in the format you want (upper-case, with leading zeroes):



    String s = Integer.toString(numberA, 36).toUpperCase();
    String result = String.format("%3s", s).replace(' ', '0');






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 12:54









    JesperJesper

    155k36251297




    155k36251297








    • 1





      Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

      – Holger
      Nov 23 '18 at 13:07
















    • 1





      Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

      – Holger
      Nov 23 '18 at 13:07










    1




    1





    Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

    – Holger
    Nov 23 '18 at 13:07







    Or String s = Integer.toString(numberA, 36); String result = String.format("000%S", s) .substring(s.length());

    – Holger
    Nov 23 '18 at 13:07













    1














    Here is code that will print 001 to zzz sequence.



    public static void main(String args){
    String result="";
    int i=0;
    while(!result.equals("ZZZ")){
    String s = Integer.toString(i, 36).toUpperCase();
    result = String.format("%3s", s).replace(' ', '0');
    System.out.println("t "+result);
    i++;
    }
    }





    share|improve this answer




























      1














      Here is code that will print 001 to zzz sequence.



      public static void main(String args){
      String result="";
      int i=0;
      while(!result.equals("ZZZ")){
      String s = Integer.toString(i, 36).toUpperCase();
      result = String.format("%3s", s).replace(' ', '0');
      System.out.println("t "+result);
      i++;
      }
      }





      share|improve this answer


























        1












        1








        1







        Here is code that will print 001 to zzz sequence.



        public static void main(String args){
        String result="";
        int i=0;
        while(!result.equals("ZZZ")){
        String s = Integer.toString(i, 36).toUpperCase();
        result = String.format("%3s", s).replace(' ', '0');
        System.out.println("t "+result);
        i++;
        }
        }





        share|improve this answer













        Here is code that will print 001 to zzz sequence.



        public static void main(String args){
        String result="";
        int i=0;
        while(!result.equals("ZZZ")){
        String s = Integer.toString(i, 36).toUpperCase();
        result = String.format("%3s", s).replace(' ', '0');
        System.out.println("t "+result);
        i++;
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 15:07









        samjisamji

        265




        265






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446748%2fincrease-number-with-character-in-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings