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. System.out.printf(games[i]+ " ");
  41. System.out.printf(at_bat[i]+ " ");
  42. System.out.printf(hits[i]+ " ");
  43. System.out.printf("%.3f",anda[i]);
  44. }
  45.  
  46. System.out.printf("\n");
  47. int allg=0;
  48. int allab=0;
  49. int allh=0;
  50. double allad=0;
  51. for(int i=0;i<games.length;i++){ //初期値0に配列の値を追加していく
  52. allg = allg+games[i];
  53. allab = allab+at_bat[i];
  54. allh = allh+hits[i];
  55. allad = (double) allh/allab;
  56. }
  57. System.out.printf("%d\n",allg);
  58. System.out.printf("%d\n",allab);
  59. System.out.printf("%d\n",allh);
  60. System.out.printf("%f\n",allad);
  61. }
  62.  
  63. }
Success #stdin #stdout 0.15s 54524KB
stdin
Standard input is empty
stdout
2010 144 554 172 0.3102011 144 557 171 0.3072013 144 527 147 0.2792014 144 532 153 0.2882015 142 533 143 0.2682009 140 569 152 0.2672008 138 527 167 0.3172016 135 477 133 0.2792019 123 409 103 0.2522021 117 387 97 0.2512017 116 333 84 0.2522018 114 305 78 0.2562007 112 302 84 0.2782020 111 372 101 0.2722012 103 394 114 0.2892022 89 239 63 0.2642005 84 286 85 0.2972023 77 157 34 0.2172006 63 142 38 0.2682024 60 124 28 0.2262025 11 23 2 0.0872026 11 13 2 0.1542004 1 3 1 0.333
2323
7765
2152
0.277141