Advertisement
wingman007

2016HelloWorld2b

Sep 17th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HelloWorld2b
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Hello Stoyan!");
  14.             // Console.BackgroundColor = ConsoleColor.Cyan;
  15.             Console.WriteLine(DateTime.Now);
  16.  
  17.             byte age = 52;
  18.             double money = 2.54;
  19.             char firstLetter = 'S';
  20.             string name = "Stoyan";
  21.             bool isMale = true;
  22.  
  23.             double sum = 0.1 + 0.2;
  24.             Console.WriteLine(sum == 0.3);
  25.  
  26.             Console.WriteLine("I am {0} years old", age);
  27.             Console.WriteLine("I have {0} USD", money);
  28.             Console.WriteLine("The first letter of my name is {0}", firstLetter);
  29.             Console.WriteLine("My name is {0}", name);
  30.             Console.WriteLine("Am I  amn? {0}", isMale);
  31.  
  32.             byte a = 3;
  33.             byte b = 1;
  34.  
  35.             Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
  36.             Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
  37.             Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
  38.             Console.WriteLine("{0} / {1} = {2}", a, b, a / b);
  39.             Console.WriteLine("{0} % {1} = {2}", a, b, a % b);
  40.             Console.WriteLine("++{0}  = {1}", a, ++a);
  41.  
  42.             // 2. comparison
  43.             Console.WriteLine("{0} < {1} = {2}", a, b, a < b);
  44.             Console.WriteLine("{0} > {1} = {2}", a, b, a > b);
  45.             Console.WriteLine("{0} <= {1} = {2}", a, b, a <= b);
  46.             Console.WriteLine("{0} >= {1} = {2}", a, b, a >= b);
  47.             Console.WriteLine("{0} == {1} = {2}", a, b, a == b);
  48.             Console.WriteLine("{0} == {1} = {2}", a, b, a != b);
  49.  
  50.             // 3. Boolean
  51.             bool c = true;
  52.             bool d = false;
  53.  
  54.             Console.WriteLine("{0} && {1} = {2}", c, d, c && d);
  55.             Console.WriteLine("{0} || {1} = {2}", c, d, c || d);
  56.             Console.WriteLine("{0} ^ {1} = {2}", c, d, c ^ d);
  57.             Console.WriteLine("!{0} = {1}", c, !c);
  58.  
  59.  
  60.             Console.WriteLine("{0} << 1 {1}", 1, 1 << 1);
  61.             Console.WriteLine("{0} >> 1 {1}", 1, 1 >> 1);
  62.             Console.WriteLine("{0} | {1} = {2}", a, b, a | b);
  63.             Console.WriteLine("{0} & {1} = {2}", a, b, a & b);
  64.             Console.WriteLine("{0} ^ {1} = {2}", a, b, a ^ b);
  65.             Console.WriteLine("~{0} = {1}", a, ~a);
  66.  
  67.             Console.WriteLine("Please, enter your age:");
  68.             string input = Console.ReadLine();
  69.             age = byte.Parse(input);
  70.  
  71.  
  72.             Console.WriteLine("In 10 years you will be {0}", age + 10);
  73.  
  74.             if (age <= 18)
  75.             {
  76.                 Console.WriteLine("You are a teenager!");
  77.             }
  78.             else if (age >= 20 && age <= 30)
  79.             {
  80.                 Console.WriteLine("You are in a golden age!");
  81.             }
  82.             else
  83.             {
  84.                 Console.WriteLine("You are an adult!");
  85.             }
  86.  
  87.             switch (age)
  88.             {
  89.                 case 22:
  90.                 case 23:
  91.                     Console.WriteLine("You are very sick!");
  92.                     break;
  93.  
  94.  
  95.             }
  96.  
  97.             Console.WriteLine(2 + 3 < 3 + 4 && 7 * 1 + 1 > 7 + 5);
  98.  
  99.             //Console.WriteLine(1);
  100.             //Console.WriteLine(2);
  101.             //Console.WriteLine(3);
  102.             //Console.WriteLine(4);
  103.  
  104.             int i = 1;
  105.             while (i <= 10)
  106.             {
  107.                 if (i == 5) break;
  108.                 Console.WriteLine(i);
  109.                 i++;
  110.             }
  111.  
  112.             i = 11;
  113.             do
  114.             {
  115.                 Console.WriteLine("do-while: {0}", i);
  116.                 i++;
  117.             } while (i <= 10);
  118.  
  119.  
  120.             //string choice = "";
  121.             //do
  122.             //{
  123.             //    Console.Clear();
  124.             //    Console.WriteLine("Добре дошли в рецептурника на шеф Манчев");
  125.             //    Console.WriteLine("Моля изберете:");
  126.             //    Console.WriteLine("1. Мусака");
  127.             //    Console.WriteLine("2. Пиле с ориз");
  128.             //    Console.WriteLine("3. Пиле със зеле");
  129.             //    // ... Do something smart
  130.             //    Console.WriteLine("4. Изход");
  131.             //    choice = Console.ReadLine();
  132.  
  133.             //    switch(choice)
  134.             //    {
  135.             //        case "1" :
  136.             //            Console.Clear();
  137.             //            Console.WriteLine("За да се върнете към главно меню натиснете кой да е клавиш!");
  138.             //            Console.WriteLine("Чушките се нарязват на едро. Ситно нарязаният лук и настърганият морков се запържват в олиото. ");
  139.             //            choice = Console.ReadLine();
  140.             //            break;
  141.             //    }
  142.  
  143.             //} while (choice != "4");
  144.  
  145.  
  146.             for (i = 0; i < 100; i++)
  147.             {
  148.                 if (i % 2 != 0) continue;
  149.                 Console.WriteLine("for : {0}", i);
  150.             }
  151.  
  152.             string[] names = { "Vilina", "Angie", "Rado",
  153.                                  "Vesi", "Milena", "Svetoslav",
  154.                                  "Simeon", "Mihaela", "Stoyan",
  155.                                  "Niki", "Alex", "Pesho", "Angel"};
  156.  
  157.             foreach (string nameSt in names)
  158.             {
  159.                 Console.WriteLine(nameSt);
  160.             }
  161.  
  162.             // string nameSt; // This is not correct
  163.  
  164.             // child block scope
  165.             {
  166.                 string nameSt; // it is OK
  167.             }
  168.  
  169.             // 1.
  170.             // int[] myArray; // = new int[5];
  171.             // myArray = new int[5];
  172.             // 2.
  173.             // int[] myArray = new int[5];
  174.             // 3.
  175.             int[] myArray = { 0, 0, 0, 0, 45, 56 };
  176.  
  177.             // myArray[4] = 45;
  178.  
  179.             for (i = 0; i < myArray.Length; i++)
  180.             {
  181.                 Console.WriteLine("myArray[{0}] = {1}", i, myArray[i]);
  182.             }
  183.  
  184.             string[,] positionOfTheStudents = {
  185.                             {"", "Vilina", "", "", "Rado", "", "", ""},
  186.                             {"Vesi", "Milena", "", "", "Simeon", "Mihaela", "", ""},
  187.                             {"", "Stoyan", "", "Niki", "Alex", "", "Petar", "Angel"},
  188.              };
  189.  
  190.             for(i = 0; i < 3; i++)
  191.             {
  192.                 for(int j = 0; j < 8; j++)
  193.                 {
  194.                     Console.WriteLine("positionOfTheStudents[{0},{1}] = {2}", i, j, positionOfTheStudents[i,j]);
  195.                 }
  196.             }
  197.  
  198.             int[][] jaggedArray;
  199.             jaggedArray = new int[2][];
  200.             jaggedArray[0] = new int[8];
  201.             jaggedArray[1] = new int[5];
  202.  
  203.             byte result = 148;
  204.             Console.WriteLine(Convert.ToString(result, 2).PadLeft(16, '0'));
  205.             Console.WriteLine();
  206.             //for(i = 0; i < 10; i++)
  207.             //{
  208.             //    Console.Write("*");
  209.             //}
  210.             //Console.WriteLine();
  211.             //for (i = 0; i < 20; i++)
  212.             //{
  213.             //    Console.Write("^");
  214.             //}
  215.  
  216.             Console.WriteLine(createString(10));
  217.             Console.WriteLine(createString(20));
  218.  
  219.             Console.WriteLine("6! = {0}", factorial(6));
  220.         }
  221.  
  222.         static string createString(int n, char c = '*')
  223.         {
  224.             string temp = "";
  225.             for (int i = 0; i < n; i++ )
  226.             {
  227.                 temp += c; // <=> temp = temp + c;
  228.             }
  229.             return temp;
  230.         }
  231.  
  232.         static int factorial(int n)
  233.         {
  234.             if (n == 0) return 1;
  235.             return factorial(n - 1) * n;
  236.         }
  237.  
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement