for (int i = 0; i < c.length; i++) { if (c[i] == null){ c[i] = ""; } c[i] += currency + " || "+prodaja + " || " + bidPrice + " || "+ commercial+ "\n"; } if (c[2] != null||(c[5]!=null)||(c[6]!=null)){ c[2]=currency + " || "+prodaja +" || "+ bidPrice +" || " +commercial; } } for (int i = 0; i < 1; i++) { System.out.print(c[i]); } 

Displays these values, but RUB, PLN, JPY, DKK and so on are not formatted.

 USD || 28.082 -0.050 || 27.761 -0.033 || 28.0195 27.930020 EUR || 32.607 -0.090 || 31.970 -0.085 || 32.3292 32.362514 RUB || 0.436 +0.003 || 0.372 +0.004 || 0.4288 0.426210 GBP || 37.380 -0.066 || 35.676 -0.088 || 36.8098 36.946462 CHF || 28.560 -0.092 || 27.101 -0.130 || 28.2307 28.279023 PLN || 7.638 +0.015 || 7.083 +0.050 || 7.5686 7.545468 JPY || 0.251 || 0.239 +0.001 || 0.2497 0.249096 CAD || 21.950 +0.265 || 20.450 +0.800 || 21.5661 21.560636 AUD || 20.330 +0.030 || 19.500 +0.070 || 19.9768 19.923976 DKK || 4.370 || 4.100 || 4.3496 4.337615 NOK || 3.460 +0.020 || 3.280 || 3.4203 3.435584 SEK || 3.160 +0.010 || 2.970 || 3.1315 3.136966 CZK || 1.297 || 1.193 || 1.2570 1.253341 HUF || 0.104 +0.001 || 0.091 || 0.1008 0.100486 

That is, I want the output of the array to be such (that is, that the separators (||) are placed one below the other:

 USD || 28.082 -0.050 || 27.761 -0.033 || 28.0195 27.930020 EUR || 32.607 -0.090 || 31.970 -0.085 || 32.3292 32.362514 RUB || 0.436 +0.003 || 0.372 +0.004 || 0.4288 0.426210 GBP || 37.380 -0.066 || 35.676 -0.088 || 36.8098 36.946462 CHF || 28.560 -0.092 || 27.101 -0.130 || 28.2307 28.279023 PLN || 7.638 +0.015 || 7.083 +0.050 || 7.5686 7.545468 JPY || 0.251 || 0.239 +0.001 || 0.2497 0.249096 CAD || 21.950 +0.265 || 20.450 +0.800 || 21.5661 21.560636 AUD || 20.330 +0.030 || 19.500 +0.070 || 19.9768 19.923976 DKK || 4.370 || 4.100 || 4.3496 4.337615 NOK || 3.460 +0.020 || 3.280 || 3.4203 3.435584 SEK || 3.160 +0.010 || 2.970 || 3.1315 3.136966 CZK || 1.297 || 1.193 || 1.2570 1.253341 HUF || 0.104 +0.001 || 0.091 || 0.1008 0.100486 

Tell me how to fix it, advise something

  • if it’s just a desire, can it all leave? - michael_best pm
  • @MishaKotor it would be nice if you only wish, can you help? - CR7
  • I think it is necessary to count the number of characters before output. Find the maximum. In the next line, if they are less than the maximum, add spaces - michael_best
  • @MishaKotor String type array - CR7
  • same question ?? - michael_best

1 answer 1

There is a format for this.

 c[i] += String.format("%s || %-15s || %-15s || %-20s\n", currency, prodaja , bidPrice, commercial); 
  • Thank you so much - CR7
  • And do not forget that in such cases you should use monospaced fonts. Although you have the same numbers there, but suddenly ... - Igor Kudryashov