There is a format number DDDDDRRRPC. It is necessary to separate C, P, RRR, DDDDDD. How can this be implemented? In Java, I am still learning more, sort of how it can be done with the help of%, but I could not do it myself

    2 answers 2

    If the positions of the characters in the number are known, then the easiest way is to use the built-in functionality for working with strings. Convert the number to a string, bite off the desired part, convert back.

    String numbStr = String.valueOf(numberCPRD); //переводим чисто в текстовый вид int numberC = Integer.parseInt(numbStr.substring(9)); //C int numberP = Integer.parseInt(numbStr.substring(8, 9)); //P int numberR = Integer.parseInt(numbStr.substring(5, 8)); //RRR int numberD = Integer.parseInt(numbStr.substring(0, 5)); //DDDDDD 
       System.out.println(Arrays.toString("DDDDDRRRPC".split("(?<=(.))(?!\\1)")));