練習用です。いろんなものがごちゃまぜです。
(empty log message)
@@ -1,13 +1,36 @@ | ||
1 | 1 | using System; |
2 | +using System.Collections.Generic; | |
3 | +using System.Linq; | |
2 | 4 | |
3 | - | |
4 | 5 | namespace chap05 |
5 | 6 | { |
6 | 7 | class Program |
7 | 8 | { |
9 | + //データを1つ読み取る | |
10 | + private static int read() | |
11 | + { | |
12 | + for (;;) | |
13 | + { | |
14 | + string s = Console.ReadLine(); | |
15 | + if (s == null) return 0; | |
16 | + int r; | |
17 | + if (int.TryParse(s, out r)) | |
18 | + { | |
19 | + return r; | |
20 | + } | |
21 | + Console.WriteLine("数値として解釈できません。再入力してください"); | |
22 | + } | |
23 | + } | |
8 | 24 | static void Main(string[] args) |
9 | 25 | { |
10 | - Class16.start(); | |
26 | + var list = new List<int>(); | |
27 | + for (;;) | |
28 | + { | |
29 | + int r = read(); | |
30 | + if (r == 0) break; | |
31 | + list.Add(r); | |
32 | + } | |
33 | + Console.WriteLine(list.Average()); | |
11 | 34 | Console.Read(); |
12 | 35 | } |
13 | 36 | } |