練習用です。いろんなものがごちゃまぜです。
| @@ -10,43 +10,9 @@ | ||
| 10 | 10 | { |
| 11 | 11 | static void Main(string[] args) |
| 12 | 12 | { |
| 13 | - int[] stoneWeights = new int[] {7,12,5,9,17}; | |
| 14 | - int min = stoneWeights[0]; | |
| 15 | - int max = stoneWeights[0]; | |
| 16 | - int upper10Count = 0; | |
| 17 | - bool existupper12 = false; | |
| 18 | - int sum = 0; | |
| 19 | - foreach(int weight in stoneWeights) | |
| 20 | - { | |
| 21 | - sum += weight; | |
| 22 | - if(weight < min) | |
| 23 | - { | |
| 24 | - min = weight; | |
| 25 | - } | |
| 26 | - if(max < weight) | |
| 27 | - { | |
| 28 | - max = weight; | |
| 29 | - } | |
| 30 | - if (10 < weight) | |
| 31 | - { | |
| 32 | - upper10Count++; | |
| 33 | - } | |
| 34 | - if (12 < weight) | |
| 35 | - { | |
| 36 | - existupper12 = true; | |
| 37 | - } | |
| 38 | - } | |
| 39 | - double avrg = sum / stoneWeights.Count(); | |
| 13 | + list1.start(args); | |
| 14 | + Console.ReadLine(); | |
| 40 | 15 | |
| 41 | - Console.WriteLine($"10kg以上の石の数は{upper10Count}個です。"); | |
| 42 | - Console.WriteLine($"最軽量の石の重さは{min}kgです。"); | |
| 43 | - Console.WriteLine($"最重量の石の重さは{max}kgです。"); | |
| 44 | - Console.WriteLine($"平均の石の重さは{avrg}kgです。"); | |
| 45 | - if (existupper12) { | |
| 46 | - Console.WriteLine("重さ12kgの石は含まれます。"); | |
| 47 | - } | |
| 48 | - | |
| 49 | - | |
| 50 | 16 | } |
| 51 | 17 | } |
| 52 | 18 | } |
| @@ -0,0 +1,51 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Linq; | |
| 4 | +using System.Text; | |
| 5 | +using System.Threading.Tasks; | |
| 6 | + | |
| 7 | +namespace chap02 | |
| 8 | +{ | |
| 9 | + class list1 | |
| 10 | + { | |
| 11 | + public static void start(string[] args) | |
| 12 | + { | |
| 13 | + int[] stoneWeights = new int[] { 7, 12, 5, 9, 17 }; | |
| 14 | + int min = stoneWeights[0]; | |
| 15 | + int max = stoneWeights[0]; | |
| 16 | + int upper10Count = 0; | |
| 17 | + bool existupper12 = false; | |
| 18 | + int sum = 0; | |
| 19 | + foreach (int weight in stoneWeights) | |
| 20 | + { | |
| 21 | + sum += weight; | |
| 22 | + if (weight < min) | |
| 23 | + { | |
| 24 | + min = weight; | |
| 25 | + } | |
| 26 | + if (max < weight) | |
| 27 | + { | |
| 28 | + max = weight; | |
| 29 | + } | |
| 30 | + if (10 < weight) | |
| 31 | + { | |
| 32 | + upper10Count++; | |
| 33 | + } | |
| 34 | + if (12 < weight) | |
| 35 | + { | |
| 36 | + existupper12 = true; | |
| 37 | + } | |
| 38 | + } | |
| 39 | + double avrg = sum / stoneWeights.Count(); | |
| 40 | + | |
| 41 | + Console.WriteLine($"10kg以上の石の数は{upper10Count}個です。"); | |
| 42 | + Console.WriteLine($"最軽量の石の重さは{min}kgです。"); | |
| 43 | + Console.WriteLine($"最重量の石の重さは{max}kgです。"); | |
| 44 | + Console.WriteLine($"平均の石の重さは{avrg}kgです。"); | |
| 45 | + if (existupper12) | |
| 46 | + { | |
| 47 | + Console.WriteLine("重さ12kgの石は含まれます。"); | |
| 48 | + } | |
| 49 | + } | |
| 50 | + } | |
| 51 | +} |