Advertisement
wingman007

IntroC#_loops_arrays_decimal_methods_recursion_2b

Sep 16th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.09 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.             int age = 214;
  14.             char firstLetter = 'S';
  15.             float money = 2.54f;
  16.             string name = "Stoyan";
  17.             bool isMail = false;
  18.             object myObject = 5;
  19.             int nextYear = age + 1;
  20.             int remainder = 10; // % 3;
  21.             remainder %= 3;
  22.  
  23.             bool test = 4 * 5 + 3 < 6 * 8 - 3;
  24.  
  25.             Console.WriteLine("Hello World!!!");
  26.             Console.WriteLine("Max Int : " + age);
  27.             Console.WriteLine("The first letter is: " + firstLetter);
  28.             Console.WriteLine("I have in my pocket : " + money);
  29.             Console.WriteLine("My name is : " + name);
  30.             Console.WriteLine("Next year I will be: " + nextYear);
  31.             Console.WriteLine(3 == 3);
  32.             Console.WriteLine(remainder);
  33.  
  34.             Console.WriteLine("Please enter your age");
  35.             string myAge = Console.ReadLine();
  36.             int myAgeInt = int.Parse(myAge);
  37.             Console.WriteLine("You told me. Your age is: {0}", ++myAgeInt);
  38.  
  39.             if (myAgeInt < 20)
  40.             {
  41.                 Console.WriteLine("You are a teenager!");
  42.             }
  43.             else if (myAgeInt > 20 && myAgeInt < 30)
  44.             {
  45.                 Console.WriteLine("It is time for fun!!!");
  46.             }
  47.             else {
  48.                 Console.WriteLine("You are aging too fast!!");
  49.             }
  50.  
  51.             switch (myAgeInt) {
  52.                 case 20:
  53.                     Console.WriteLine("You are {0} years old", myAgeInt);
  54.                     break;
  55.                 case 30:
  56.                     Console.WriteLine("You are {0} years old", myAgeInt);
  57.                     break;
  58.                 default :
  59.                     Console.WriteLine("I don't know  what to say.");
  60.                     break;
  61.             }
  62.  
  63.  
  64.             Console.WriteLine(1);
  65.             Console.WriteLine(2);
  66.             Console.WriteLine(3);
  67.             // ...
  68.             Console.WriteLine("1\n2\n3\n");
  69.  
  70.             int i = 1;
  71.             while (i <= 10)
  72.             {
  73.                 if (i == 5) break;
  74.                 Console.WriteLine(i);
  75.                 i++;
  76.             }
  77.  
  78.             // break
  79.             Console.WriteLine("Please choose:");
  80.             Console.WriteLine("1. List the partitions");
  81.             Console.WriteLine("2. Create a Partionion");
  82.             Console.WriteLine("3. Delete Partition");
  83.             Console.WriteLine("4. Exit");
  84.             string choice;
  85.             while (true)
  86.             {
  87.                 choice = Console.ReadLine();
  88.                 if (int.Parse(choice) == 4) break;
  89.                 Console.WriteLine("Your choice was:" + choice);
  90.             }
  91.  
  92.  
  93.             // do-while
  94.             i = 10;
  95.  
  96.             do
  97.             {
  98.                 Console.WriteLine("do-while: {0}", i);
  99.                 i++;
  100.             } while (i < 10);
  101.  
  102.  
  103.             // for
  104.             for (int j = 0; j < 10; j++)
  105.             {
  106.                 if (j % 2 != 1)
  107.                 {
  108.                     continue;
  109.                 }
  110.  
  111.                 // if (j % 2 == 1) continue;
  112.  
  113.                 Console.WriteLine("for: {0}", j);
  114.             }
  115.  
  116.             string[] group2b = { "Swetla", "Lyubo", "Krasi", "Borko", "Blago", "Miryana", "Niki", "Wqra", "Yoana" };
  117.  
  118.             foreach (string stname in group2b)
  119.             {
  120.                 Console.WriteLine("Name: {0}", stname);
  121.             }
  122.  
  123.             for (i = 0; i < 10; i++)
  124.             {
  125.                 for (int j = 0; j < i; j++)
  126.                 {
  127.                     Console.Write("*");
  128.                 }
  129.                 Console.Write("\n");
  130.             }
  131.  
  132.             // array
  133.             /* 1)
  134.             int[] myArray;
  135.             myArray = new int[5];
  136.             myArray[3] = 45;
  137.             myArray[0] = 1;
  138.             */
  139.             // 2)  int[] myArray = { 12, 34, 54, 67 };
  140.  
  141.             // 3)
  142.             int[] myArray = new int[3] { 12, 34, 54 };
  143.  
  144.  
  145.             for (i = 0; i < myArray.Length; i++)
  146.             {
  147.                 Console.WriteLine(myArray[i]);
  148.             }
  149.  
  150.            
  151.             string[,] positionsOfTheStudents = {
  152.                 {"", "Vyara","","","Swetla","Lyubo","Krasi","Borko"},
  153.                 {"Yoana", "","","","","","","Blago"},
  154.                 {"", "","","","Niki","","","Miryana"}
  155.             };
  156.  
  157.             for (i = 0; i < positionsOfTheStudents.GetLength(0); i++) {
  158.                 Console.Write("Red {0}: ", i);
  159.                 for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++) {
  160.                     Console.Write(" {0}", positionsOfTheStudents[i,j]);
  161.                 }
  162.                 Console.WriteLine();
  163.             }
  164.  
  165.             /*
  166.             int[,] test23 = {
  167.                 {12,34},
  168.                 {23,45}
  169.             };
  170.             */
  171.  
  172.             int[][] jaggedArray;
  173.             jaggedArray = new int[2][];
  174.             jaggedArray[0] = new int[8];
  175.             jaggedArray[1] = new int[5];
  176.  
  177.             Console.WriteLine(createString(10));
  178.             Console.WriteLine(createString(4));
  179.             Console.WriteLine(createString(11, "+"));
  180.             Console.WriteLine(createString(11, "+", "Stoyan", "Yoana", "Vqra"));
  181.  
  182.             Console.WriteLine(factorial(4));
  183.         }
  184.  
  185.         static string createString(int strLength, string str = "*", params string[] par)
  186.         {
  187.             string temp = "";
  188.             for (int i = 0; i < strLength; i++) {
  189.                 temp += str; // "*";
  190.             }
  191.             foreach (string item in par) {
  192.                 Console.WriteLine(item);
  193.             }
  194.             return temp;
  195.         }
  196.  
  197.         static string createString() {
  198.             return "Hahha";
  199.         }
  200.  
  201.         static int factorial(int n) {
  202.             if (n == 0) return 1;
  203.             // n--;
  204.             return factorial(n - 1) * n; // --n changes the value of n
  205.         }
  206.  
  207.     }
  208.  
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement