Условный оператор. Циклы. (C-Sharp)
Версия от 11:53, 9 июня 2021; Безуглов Сергей (обсуждение | вклад)
Условный оператор
1 using System;
2
3 namespace HelloCS
4 {
5 class Program
6 {
7 static void Main(string[] args)
8 {
9 Console.WriteLine("Please enter water temperature in degrees celsius::");
10 string tempString = Console.ReadLine();
11 int temp = Convert.ToInt32(tempString);
12 if (temp > 65)
13 {
14 Console.WriteLine("Water is boiling.");
15 }
16 else
17 {
18 Console.WriteLine("Not hot enough.");
19 }
20
21 Console.WriteLine((temp % 2 == 0) ? "Temperature is even" : "Temperature is odd");
22
23 switch (DateTime.Now.DayOfWeek)
24 {
25 case DayOfWeek.Saturday:
26 case DayOfWeek.Sunday:
27 Console.WriteLine("The weekend");
28 break;
29 case DayOfWeek.Monday:
30 Console.WriteLine("The first day of the work week.");
31 break;
32 case DayOfWeek.Friday:
33 Console.WriteLine("The last day of the work week.");
34 break;
35 default:
36 Console.WriteLine("The middle of the work week.");
37 break;
38 }
39 }
40 }
41 }
Циклы
1 Console.WriteLine("while loop");
2 i = 1;
3 while (i < 11)
4 {
5 Console.WriteLine(i);
6 i++;
7 }
8
9 Console.WriteLine("do while loop");
10 i = 1;
11 do
12 {
13 Console.WriteLine(i);
14 i++;
15 } while (i < 11);
16
17 Console.WriteLine("for loop");
18 for (int j = 1; j < 11; j++)
19 {
20 Console.WriteLine(j);
21 }