Условный оператор. Циклы. (C-Sharp)

Материал из Информационная безопасностя
Перейти к навигации Перейти к поиску

Условный оператор

 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 using System;
 2 
 3 namespace HelloCS
 4 {
 5     class Program
 6     {
 7         static void Main(string[] args)
 8         {
 9             Console.WriteLine("while loop");
10             int i = 1;
11             while (i < 11)
12             {
13                 Console.WriteLine(i);
14                 i++;
15             }
16 
17             Console.WriteLine("do while loop");
18             i = 1;
19             do
20             {
21                 Console.WriteLine(i);
22                 i++;
23             } while (i < 11);
24 
25             Console.WriteLine("for loop");
26             for (int j = 1; j < 11; j++)
27             {
28                 Console.WriteLine(j);
29             }
30         }
31     }
32 }

Задачник