Advertisement
wingman007

2016HelloWorld2a

Sep 17th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.80 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 HelloWorld2a
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int first = 13;
  14.             int second = 2;
  15.             double result = (double)first / second;
  16.             Console.WriteLine(result);
  17.  
  18.             Console.WriteLine("Hello World!");
  19.  
  20.             int age = 0;
  21.  
  22.             Console.WriteLine("Please enter your age?");
  23.             string input = Console.ReadLine();
  24.  
  25.             try
  26.             {
  27.                 age = int.Parse(input);
  28.             }
  29.             catch (System.FormatException e)
  30.             {
  31.                 Console.WriteLine("Incorect data!!! {0}", e.Message);
  32.                 // throw new System.
  33.             }
  34.             finally
  35.             {
  36.                 Console.WriteLine("I am always executed!");
  37.             }
  38.  
  39.  
  40.             if (age <= 20)
  41.             {
  42.                 Console.WriteLine("You are a teenager!");
  43.             }
  44.             else if (age > 20 && age <= 30)
  45.             {
  46.                 Console.WriteLine("You are in a perfect age");
  47.             }
  48.             else
  49.             {
  50.                 Console.WriteLine("I don't know what to say");
  51.             }
  52.  
  53.             switch (age)
  54.             {
  55.  
  56.                 case 23:
  57.                     Console.WriteLine("You are 23 years old!");
  58.                     break;
  59.  
  60.                 case 43:
  61.                 case 34:
  62.                     Console.WriteLine("Bad magic!");
  63.                     break;
  64.                 default:
  65.                     Console.WriteLine("I don't know!");
  66.                     break;
  67.             }
  68.  
  69.  
  70.  
  71.  
  72.             Console.WriteLine("In 10 years you will be " + (age + 10));
  73.             // long myLong = -3123213L;
  74.             // byte, sbyte, short, ushort, int, uint, long, ulong
  75.  
  76.             double money = 2.54;
  77.             float money1 = 3.45f;
  78.             double sum1 = 2.1;
  79.             double sum2 = 1.04;
  80.             double sum = sum1 + sum2;
  81.  
  82.             double fix = 3.14;
  83.  
  84.             decimal myDec = 23.456m;
  85.  
  86.             char letter = 'S';// '\u000f';
  87.  
  88.             string name = "Zlatomira";
  89.  
  90.             bool _myVar = true; // false
  91.  
  92.             bool pr = (1 + 2) * 8 % 4 > 23 + 45 % 34;
  93.  
  94.             Console.WriteLine(sum == fix);
  95.  
  96.             Console.Beep(2130, 321);
  97.  
  98.             Console.WriteLine(age);
  99.  
  100.             Console.WriteLine(pr);
  101.  
  102.             age = age + 1; // ++age
  103.  
  104.             age += 1;
  105.  
  106.             Console.WriteLine(DateTime.Now);
  107.             Console.WriteLine(age);
  108.  
  109.  
  110.             Console.WriteLine(1);
  111.             Console.WriteLine(2);
  112.             Console.WriteLine(3);
  113.             Console.WriteLine(4);
  114.  
  115.             int i = 1;
  116.             while (i <= 10)
  117.             {
  118.                 Console.WriteLine(i);
  119.                 i++;
  120.             }
  121.  
  122.             do
  123.             {
  124.                 Console.WriteLine("Please enter your age:");
  125.                 try
  126.                 {
  127.                     input = Console.ReadLine();
  128.                     age = byte.Parse(input);
  129.                 }
  130.                 catch (System.FormatException e)
  131.                 {
  132.                     Console.WriteLine(e.Message);
  133.                     age = -1;
  134.                 }
  135.  
  136.                 if (age == 0) {
  137.                     Console.WriteLine("You are too young for me. I don't want to deal with you!");
  138.                     break;
  139.                 }
  140.  
  141.             } while (age < 0);
  142.  
  143.             i = 11;
  144.             do
  145.             {
  146.                 Console.WriteLine("do while: {0}", i);
  147.             } while (i <= 10);
  148.  
  149.             Console.WriteLine("The correct age is {0}", age);
  150.  
  151.             for (i = 0; i <= 10; i++)
  152.             {
  153.                 if (i % 2 == 1)
  154.                 {
  155.                     continue;
  156.                 }
  157.  
  158.                 if (i % 2 == 0)
  159.                 {
  160.                     Console.WriteLine("for i = {0}", i);
  161.                 }    
  162.             }
  163.  
  164.             string[] names = { "Vasil", "Petko", "Mitko", "Rangel", "Yani", "Nelina", "Detelina"};
  165.  
  166.             foreach (string nameStudent in names)
  167.             {
  168.                 if (nameStudent == "Mitko")
  169.                 {
  170.                     Console.WriteLine("I found a student with name Mitko!");
  171.                     break;
  172.                 }
  173.                 Console.WriteLine(nameStudent);
  174.             }
  175.  
  176.             /* 1.
  177.             int[] myArray;
  178.             myArray = new int[7];
  179.             myArray[6] = 45;
  180.  
  181.             */
  182.             // 2.
  183.             // int[] myArray = new int[7];
  184.  
  185.             // 3.
  186.             int[] myArray = { 54, 65, 65, 76, 67, 76, 89};
  187.  
  188.  
  189.             for (i = 0; i < myArray.Length; i++)
  190.             {
  191.                 Console.WriteLine("MyArra[{0}] = {1}", i, myArray[i]);
  192.             }
  193.  
  194.             string[,] positionsOfTheStudents = {
  195.                    {"", "","","","Vasko","Petko", "","Maria"},
  196.                    {"Milena", "Sofia","","Musti","Virginia","", "","Slavcho"},
  197.                    {"Borislav", "Venci","","Rado","","", "",""}
  198.             };
  199.  
  200.             for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
  201.             {
  202.                 Console.Write("Red {0}: ", i);
  203.                 for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
  204.                 {
  205.                     Console.Write(" {0}", positionsOfTheStudents[i, j]);
  206.                 }
  207.                 Console.WriteLine();
  208.             }
  209.  
  210.             int[][] jaggedArray;
  211.             // int[,][] jaggedArray = new int[2,3][];
  212.  
  213.             jaggedArray = new int[2][];
  214.             jaggedArray[0] = new int[8];
  215.             jaggedArray[1] = new int[5];
  216.  
  217.             byte resultTest = 148;
  218.  
  219.             Console.WriteLine(Convert.ToString(resultTest, 2).PadLeft(16, '0'));
  220.             // Console.WriteLine("{0,10:C4}", 148);
  221.             Console.WriteLine("{0,10:X}", resultTest);
  222.             /*
  223.             for (i = 0; i < 10; i++)
  224.             {
  225.                 Console.Write('^');
  226.             }
  227.  
  228.             for (i = 0; i < 5; i++)
  229.             {
  230.                 Console.Write('*');
  231.             }
  232.             */
  233.  
  234.             Console.WriteLine(createString(10, '^', "Stoyan", "Mariya"));
  235.  
  236.             Console.WriteLine("4! = {0}", factorial(4));
  237.             Console.WriteLine("4! = {0}", factorialIteration(4));
  238.  
  239.             Console.WriteLine(23 + 45 + 45 + "23 this will be concatinated instead of added there is a string operad!"); // 11323 this will be concatinated instead of added there is a string operad!
  240.             Console.WriteLine(13 / 2); // 6 integer divide by integer gives integer
  241.             Console.WriteLine(13 / 2.0 ); // 6.5 integer divided by double gives double
  242.            
  243.             DateTime timeNow = DateTime.Now;
  244.             timeNow = timeNow.AddYears(2);
  245.             Console.WriteLine(timeNow); // 15.9.2018 г. 13:24:17 ч.
  246.  
  247.             DateTime myDateTime = new DateTime();
  248.             Console.WriteLine(myDateTime); // 1.1.0001 г. 00:00:00 ч.
  249.  
  250.             string myString = new String('*', 10);
  251.             Console.WriteLine(myString);
  252.         }
  253.  
  254.         static string createString(int strLength, char str = '*', params string[] extra)
  255.         {
  256.             string temp = "";
  257.             for (int i = 0; i < strLength; i++)
  258.             {
  259.                 temp += str;
  260.             }
  261.  
  262.             return temp;
  263.         }
  264.  
  265.         static int factorial(int i)
  266.         {
  267.             if (i == 0) return 1;
  268.             return factorial(i - 1) * i;
  269.         }
  270.  
  271.         static int factorialIteration(int n)
  272.         {
  273.             var factorial = 1;
  274.             for (int i = 1; i <= n; i++)
  275.             {
  276.                 factorial *= i;
  277.             }
  278.  
  279.             return factorial;
  280.         }
  281.     }
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement