C# / .NETin-browser interpreter · runs locally
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System; class Product { public string Name; public double Price; public Product(string n, double p) { Name = n; Price = p; } } class Program { static void Main() { Product[] products = new Product[] { new Product("Keyboard", 40), new Product("Monitor", 220), new Product("Mouse", 25), new Product("Desk", 180) }; int count = 0; double sum = 0; for (int i = 0; i < products.Length; i++) { if (products[i].Price > 50) { Console.WriteLine(products[i].Name); count++; sum += products[i].Price; } } Console.WriteLine("count = " + count); Console.WriteLine("sum = " + sum); Console.WriteLine("avg = " + (count > 0 ? sum / count : 0)); } }
31 lines
Output
Write some code, then press Run. Stdout and errors appear here.