fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final List<String> temperatures = Arrays.asList("70.3", "700.8", "73.8", "77.0", "80.7", "83.4", "84.5", "84.4", "83.4", "80.2");
  13. final List<String> humidity = Arrays.asList("69", "670", "66", "64", "66", "69", "67", "67", "70", "69");
  14.  
  15. final Integer[] context = new Integer[temperatures.size()];
  16. final Integer spacing = 2;
  17.  
  18. final StringBuilder sb = new StringBuilder();
  19.  
  20. for(int i =0; i < temperatures.size(); ++i) {
  21. final String str = temperatures.get(i);
  22. final Integer totalSpace = str.length() + spacing;
  23. final String formatted = String.format("%-"+ totalSpace +"s", str);
  24. context[i] = totalSpace;
  25. sb.append(formatted);
  26. }
  27.  
  28. sb.append("\n");
  29.  
  30. for(int i =0; i < humidity.size(); ++i) {
  31. final String str = humidity.get(i);
  32. final String formatted = String.format("%-"+ context[i] +"s", str);
  33. sb.append(formatted);
  34. }
  35.  
  36. System.out.println(sb.toString());
  37.  
  38. }
  39. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
70.3  700.8  73.8  77.0  80.7  83.4  84.5  84.4  83.4  80.2  
69    670    66    64    66    69    67    67    70    69