| 20 | return result; |
| 21 | } |
| 22 | public String line(String words[],int start,int end, int Linelen,int max) |
| 23 | { |
| 24 | StringBuilder a = new StringBuilder(); |
| 25 | int p=1,q=0; |
| 26 | if(end!=start) |
| 27 | { |
| 28 | p=(max-Linelen)/(end-start); |
| 29 | q=(max-Linelen)%(end-start); |
| 30 | } |
| 31 | |
| 32 | for(int i=start;i<=end;i++) |
| 33 | { |
| 34 | a.append(words[i]); |
| 35 | if(i!=end) |
| 36 | { |
| 37 | if(end==words.length-1) a.append(" "); |
| 38 | else { |
| 39 | for(int j=1;j<=p;j++) a.append(" "); |
| 40 | // extra spaces |
| 41 | if(q-->=1) a.append(" "); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | // spaces in the last line |
| 46 | while(a.length()<max) a.append(" "); |
| 47 | return a.toString(); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | |