Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HelloWorld2a
- {
- class Program
- {
- static void Main(string[] args)
- {
- int first = 13;
- int second = 2;
- double result = (double)first / second;
- Console.WriteLine(result);
- Console.WriteLine("Hello World!");
- int age = 0;
- Console.WriteLine("Please enter your age?");
- string input = Console.ReadLine();
- try
- {
- age = int.Parse(input);
- }
- catch (System.FormatException e)
- {
- Console.WriteLine("Incorect data!!! {0}", e.Message);
- // throw new System.
- }
- finally
- {
- Console.WriteLine("I am always executed!");
- }
- if (age <= 20)
- {
- Console.WriteLine("You are a teenager!");
- }
- else if (age > 20 && age <= 30)
- {
- Console.WriteLine("You are in a perfect age");
- }
- else
- {
- Console.WriteLine("I don't know what to say");
- }
- switch (age)
- {
- case 23:
- Console.WriteLine("You are 23 years old!");
- break;
- case 43:
- case 34:
- Console.WriteLine("Bad magic!");
- break;
- default:
- Console.WriteLine("I don't know!");
- break;
- }
- Console.WriteLine("In 10 years you will be " + (age + 10));
- // long myLong = -3123213L;
- // byte, sbyte, short, ushort, int, uint, long, ulong
- double money = 2.54;
- float money1 = 3.45f;
- double sum1 = 2.1;
- double sum2 = 1.04;
- double sum = sum1 + sum2;
- double fix = 3.14;
- decimal myDec = 23.456m;
- char letter = 'S';// '\u000f';
- string name = "Zlatomira";
- bool _myVar = true; // false
- bool pr = (1 + 2) * 8 % 4 > 23 + 45 % 34;
- Console.WriteLine(sum == fix);
- Console.Beep(2130, 321);
- Console.WriteLine(age);
- Console.WriteLine(pr);
- age = age + 1; // ++age
- age += 1;
- Console.WriteLine(DateTime.Now);
- Console.WriteLine(age);
- Console.WriteLine(1);
- Console.WriteLine(2);
- Console.WriteLine(3);
- Console.WriteLine(4);
- int i = 1;
- while (i <= 10)
- {
- Console.WriteLine(i);
- i++;
- }
- do
- {
- Console.WriteLine("Please enter your age:");
- try
- {
- input = Console.ReadLine();
- age = byte.Parse(input);
- }
- catch (System.FormatException e)
- {
- Console.WriteLine(e.Message);
- age = -1;
- }
- if (age == 0) {
- Console.WriteLine("You are too young for me. I don't want to deal with you!");
- break;
- }
- } while (age < 0);
- i = 11;
- do
- {
- Console.WriteLine("do while: {0}", i);
- } while (i <= 10);
- Console.WriteLine("The correct age is {0}", age);
- for (i = 0; i <= 10; i++)
- {
- if (i % 2 == 1)
- {
- continue;
- }
- if (i % 2 == 0)
- {
- Console.WriteLine("for i = {0}", i);
- }
- }
- string[] names = { "Vasil", "Petko", "Mitko", "Rangel", "Yani", "Nelina", "Detelina"};
- foreach (string nameStudent in names)
- {
- if (nameStudent == "Mitko")
- {
- Console.WriteLine("I found a student with name Mitko!");
- break;
- }
- Console.WriteLine(nameStudent);
- }
- /* 1.
- int[] myArray;
- myArray = new int[7];
- myArray[6] = 45;
- */
- // 2.
- // int[] myArray = new int[7];
- // 3.
- int[] myArray = { 54, 65, 65, 76, 67, 76, 89};
- for (i = 0; i < myArray.Length; i++)
- {
- Console.WriteLine("MyArra[{0}] = {1}", i, myArray[i]);
- }
- string[,] positionsOfTheStudents = {
- {"", "","","","Vasko","Petko", "","Maria"},
- {"Milena", "Sofia","","Musti","Virginia","", "","Slavcho"},
- {"Borislav", "Venci","","Rado","","", "",""}
- };
- for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
- {
- Console.Write("Red {0}: ", i);
- for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
- {
- Console.Write(" {0}", positionsOfTheStudents[i, j]);
- }
- Console.WriteLine();
- }
- int[][] jaggedArray;
- // int[,][] jaggedArray = new int[2,3][];
- jaggedArray = new int[2][];
- jaggedArray[0] = new int[8];
- jaggedArray[1] = new int[5];
- byte resultTest = 148;
- Console.WriteLine(Convert.ToString(resultTest, 2).PadLeft(16, '0'));
- // Console.WriteLine("{0,10:C4}", 148);
- Console.WriteLine("{0,10:X}", resultTest);
- /*
- for (i = 0; i < 10; i++)
- {
- Console.Write('^');
- }
- for (i = 0; i < 5; i++)
- {
- Console.Write('*');
- }
- */
- Console.WriteLine(createString(10, '^', "Stoyan", "Mariya"));
- Console.WriteLine("4! = {0}", factorial(4));
- Console.WriteLine("4! = {0}", factorialIteration(4));
- 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!
- Console.WriteLine(13 / 2); // 6 integer divide by integer gives integer
- Console.WriteLine(13 / 2.0 ); // 6.5 integer divided by double gives double
- DateTime timeNow = DateTime.Now;
- timeNow = timeNow.AddYears(2);
- Console.WriteLine(timeNow); // 15.9.2018 г. 13:24:17 ч.
- DateTime myDateTime = new DateTime();
- Console.WriteLine(myDateTime); // 1.1.0001 г. 00:00:00 ч.
- string myString = new String('*', 10);
- Console.WriteLine(myString);
- }
- static string createString(int strLength, char str = '*', params string[] extra)
- {
- string temp = "";
- for (int i = 0; i < strLength; i++)
- {
- temp += str;
- }
- return temp;
- }
- static int factorial(int i)
- {
- if (i == 0) return 1;
- return factorial(i - 1) * i;
- }
- static int factorialIteration(int n)
- {
- var factorial = 1;
- for (int i = 1; i <= n; i++)
- {
- factorial *= i;
- }
- return factorial;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement