fork(1) 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. int[] year ={2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026};
  13. int[] at_bat ={3,286,142,302,527,569,554,557,394,527,532,533,477,333,305,409,372,387,239,157,124,23,13};
  14. int[] hits ={1,85,38,84,167,152,172,171,114,147,153,143,133,84,78,103,101,97,63,34,28,2,2};
  15. int[] games ={1,84,63,112,138,140,144,144,103,144,144,142,135,116,114,123,111,117,89,77,60,11,11};
  16. double[] anda = new double[games.length];
  17. for(int i=0;i<games.length;i++){ //ソート開始
  18. for(int j = i+1;j<games.length;j++){ //i+1~最後までを比較
  19. if(games[i]<games[j]){
  20. int a = year[i];
  21. year[i] = year[j];
  22. year[j] = a;
  23. int b = at_bat[i];
  24. at_bat[i] = at_bat[j];
  25. at_bat[j] = b;
  26. int c = hits[i];
  27. hits[i] = hits[j];
  28. hits[j] = c;
  29. int d = games[i];
  30. games[i] =games[j];
  31. games[j] = d; //比較したとき大きいとき値を代入
  32. }
  33. }
  34. }
  35. for(int i=0;i<hits.length;i++){ //打率の計算
  36. anda[i] = (double) hits[i]/at_bat[i];
  37. }
  38. for(int i=0;i<year.length;i++){
  39. System.out.printf(year[i]+ " ");
  40. }
  41. System.out.printf("\n");
  42. for(int i=0;i<at_bat.length;i++){
  43. System.out.printf(at_bat[i]+ " ");
  44. }
  45. System.out.printf("\n");
  46. for(int i=0;i<hits.length;i++){
  47. System.out.printf(hits[i]+ " ");
  48. }
  49. System.out.printf("\n");
  50. for(int i=0;i<games.length;i++){
  51. System.out.printf(games[i]+ " ");
  52. }
  53. System.out.printf("\n");
  54. for(int i=0;i<anda.length;i++){
  55. System.out.printf("%.3f",anda[i]);
  56. }
  57. System.out.printf("\n");
  58. int allg=0;
  59. int allab=0;
  60. int allh=0;
  61. double allad=0;
  62. for(int i=0;i<games.length;i++){ //初期値0に配列の値を追加していく
  63. allg = allg+games[i];
  64. allab = allab+at_bat[i];
  65. allh = allh+hits[i];
  66. allad = (double) allh/allab;
  67. }
  68. System.out.printf("%d\n",allg);
  69. System.out.printf("%d\n",allab);
  70. System.out.printf("%d\n",allh);
  71. System.out.printf("%f\n",allad);
  72. }
  73.  
  74. }
Success #stdin #stdout 0.12s 56476KB
stdin
Standard input is empty
stdout
2010 2011 2013 2014 2015 2009 2008 2016 2019 2021 2017 2018 2007 2020 2012 2022 2005 2023 2006 2024 2025 2026 2004 
554 557 527 532 533 569 527 477 409 387 333 305 302 372 394 239 286 157 142 124 23 13 3 
172 171 147 153 143 152 167 133 103 97 84 78 84 101 114 63 85 34 38 28 2 2 1 
144 144 144 144 142 140 138 135 123 117 116 114 112 111 103 89 84 77 63 60 11 11 1 
0.3100.3070.2790.2880.2680.2670.3170.2790.2520.2510.2520.2560.2780.2720.2890.2640.2970.2170.2680.2260.0870.1540.333
2323
7765
2152
0.277141