0

I am making a project in Number Theory and i want to display
some formatting text in a textArea in my Gui.
I have a method named padding which takes an integer as an argument
and return a String consisitng of a number of spaces.
This number is 12 - the number of the given integer length.

     public String padding(int number){
               int NumberOfDigits ;
               String padding = "";
                NumberOfDigits = 12 - Integer.toString(number).length();
                    for (int j = 0; j < NumberOfDigits; j++) {
                       padding +=" "; 
                        }
                    return padding;
           }

I am using this method like this :

            for (i = 2 ; i < number; i++){
              if (isPrime(i) && (number % i == 0)){
          textAreastring +=   padding(number) + number + padding(number) + " : " + padding(i) + i + padding( i) + " = " + padding( number / i) + number / i + " " + newline;
                    listint.add(i);
                    number = number/i;
                    i--;                        
                }

Is there a way using String methods to produce the same formatting?

Edited by nikolaos

2
Contributors
2
Replies
11
Views
3 Years
Discussion Span
Last Post by nikolaos
1

Yes.

String's format method uses java.util.Formatter format specs (based on C's printf) to format data into strings with specified padding, decimal places etc etc etc

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.