printing - How can I print out in columns in java -


This is where I'm printing and I need to print in the column. aLeaderboard is an array list with a custom category. It has many different instances

  System.out.println ("played the state team home wins home draw home loss home goal is to win away for home goal" Goal goal for goal goal targets total score "); (Int counter = 0; counter 
TeamName.size (counter ++) {System.out.print (+ 1 counter) + TeamNameGet (counter) + "(aLeaderboard.get ( Counter)) .getGamesPlayed () + "(aLeaderboard.get (counter)) getHomeWins () +" (aLeaderboard.get (counter)) getHomeDraws () + ""); System out.print (aLeaderboard.get) (Counter)) getHomeLosses () + "(aLeaderboard.get (counter)). GetAwayWins () + "(aLeaderboard.get (counter)) GetAwayWins () +" "(ALeaderboard.get (counter)) GetAwayDraws () +" "); System.out.print ((aLeaderboard.get ( Counter) GetHomeGoalsfor (++) "(aLeaderboard.get (counter)) GetHomeGoalsAgainst () +" (aLeaderboard.get (counter)) GetAwayLosses () + "" + (ALeaderboard.get (counter) ) GetGamesPlayed () + ""); getAwayGoalsFor (+) (aLeaderboard.get (counter)) GetAwayGoalsAgainst () + "(aLeaderboard.get (counter)). GetGoalsDifference () + "" + (ALeaderboard.get (counter)). GetTotalPoints ()); Println (); }

I use the System.out.printf (...) And to help ensure that you use a test string, line up all the columns then you can print things easily in the loop.

For example:

  import java.text.NumberFormat; Import java.util.ArrayList; Import java.util.list; Public category Foo4 {public static zero main (string [] args) {list & lt; Bar 4 & gt; Bar4List = new arrelisted & lt; & Gt; (); Bar4List.add (new bar 4 ("Donald", 3, "A", 22.42)); Bar4List.add (New Bar 4 ("Duck", 100, "B", Math. PI)); Bar4List.add (new bar 4 ("Hermann", 20, "C", Math.Sqrt (20))); String title template = "% -10s% 6s% 6s% 9s% n"; String template = "% -10s% 6d% 6s% 9s% n"; System.out.printf (title heading, "name", "value", "grade", "cost"); (Bar4 bar4: bar4List) {System.out.printf (Template, bar4.getName (), bar4.getValue (), bar4.getGrade (), bar4.getCostString ()) for; }}} Class bar 4 {private string name; Private int values; Private string grade; Private double cost; Private number format currency format = number format.getcurrencyinstance (); Public bar 4 (string name, int value, string grade, double cost) {this.name = name; This.value = value; This.grade = Grade; This.cost = cost; } Public string getName () {return name; } Public int getValue () {return value; } Public string grid () {return grade; } Public double getCost () {return cost; } Public string getCostString () {return currency Format.format (cost); }}   

which will return:

  The name value grade cost Donald 3 $ 22.42 duck 100b $ 3.14 Herman 20c $ 4.47   

For more details about the user of string format specification (i.e. above,% 6d and% 6s above), please refer to it.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -