Advertisement
wingman007

IntroC#_loops_arrays_decimal_methods_recursion_1a

Sep 16th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.93 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 HelloWorld
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int age = 50;
  14.             int colegeTest = 10 + ++age;
  15.             age +=23;
  16.             int test2 = 10 + 34* 8;
  17.             char firstLetter = 'S';
  18.             float myMoney = 2.34f;
  19.             string name = "Stoyan";
  20.             sbyte test = -128;
  21.             bool isMail = true;
  22.  
  23.             object myObject = 5;
  24.  
  25.             int result = age + test;
  26.  
  27.             bool logResult = age < test;
  28.  
  29.             Console.WriteLine("Hello World! I am " + age + " years old. My name starts with " + firstLetter + "My money " + myMoney);
  30.             Console.WriteLine("My name is " + name + test);
  31.             Console.WriteLine("My I a mail: " + isMail);
  32.             Console.WriteLine("Result " + result);
  33.             Console.WriteLine("loResult " + logResult);
  34.             Console.WriteLine("colege " + colegeTest);
  35.  
  36.            //  string readCOnsole = Console.ReadLine();
  37.            //  Console.WriteLine("You have entered " + int.Parse(readCOnsole));
  38.  
  39.             Console.WriteLine("Please eneter your age: ");
  40.             int userAge = int.Parse(Console.ReadLine());
  41.  
  42.             /*
  43.             if (userAge < 20)
  44.             {
  45.                 Console.WriteLine("You are an teenager!!!");
  46.             }
  47.             else if (userAge < 50 && userAge > 30) {
  48.                 Console.WriteLine("You are in the middle age");
  49.             }
  50.             else {
  51.                 Console.WriteLine("You are not in our age ranges");
  52.             }
  53.             */
  54.  
  55.             switch (userAge)
  56.             {
  57.                 case 20:
  58.                     Console.WriteLine("You are 20 years old");
  59.                     break;
  60.                
  61.                 default:
  62.                     Console.WriteLine("Nothing else matches");
  63.                     break;
  64.             }
  65.  
  66.             Console.WriteLine(1);
  67.             Console.WriteLine(2);
  68.             Console.WriteLine(3);
  69.  
  70.             int i = 1;
  71.             while (i <= 10) {
  72.                 if (i == 5) break;
  73.                 Console.WriteLine(i);
  74.                 i++;
  75.             }
  76.  
  77.             Console.WriteLine("Please choose [1-4]:");
  78.             Console.WriteLine("1. List all partiotions");
  79.             Console.WriteLine("2. Create a partiotn");
  80.             Console.WriteLine("3. Deletae a partition");
  81.             Console.WriteLine("4. Exit");
  82.             string choice = "";
  83.             while (true) {
  84.                 choice = Console.ReadLine();
  85.                 if (choice == "4") {
  86.                     break;
  87.                 }
  88.             }
  89.  
  90.             i = 11;
  91.             do
  92.             {
  93.                 Console.WriteLine("do: {0}", i);
  94.                 i++;
  95.             } while (i <= 10);
  96.  
  97.             for (i = 0; i < 10; i++) {
  98.                 if (i % 2 != 1) continue;
  99.                 Console.WriteLine("for: {0} ", i);
  100.             }
  101.  
  102.             string[] group1a = { "Rayna", "Mimi", "Velina", "Svetlin", "Aysun", "Maria", "Geri", "Marin", "Plamen" };
  103.  
  104.             Console.WriteLine("The list of group 1a:");
  105.             foreach (string nameGr in group1a) {
  106.                 Console.WriteLine(nameGr);
  107.             }
  108.  
  109.             int k;
  110.             for (i = 0, k = 10; i < 10; i++) {
  111.                 for (int j = 0; j < i; j++) {
  112.                     Console.Write("*");
  113.                 }
  114.                 Console.WriteLine();
  115.             }
  116. /*          // 1)
  117.             int[] myArray;
  118.             myArray = new int[5];
  119.             myArray[4] = 43;
  120. */
  121.             // 2)
  122.             // int[] myArray = { 34, 45, 56 };
  123.  
  124.             int[] myArray = new int[4] { 23, 45, 56, 78 };
  125.  
  126.             for (i = 0; i < myArray.Length; i++) {
  127.                 Console.WriteLine("myArray[{1}] = {0}", myArray[i], i);
  128.             }
  129.  
  130.             string[,] positionsOfTheStudents = {
  131.                    {"", "Rayna","","","Mimi","", "Velina",""},
  132.                    {"", "Svetlin","","Aisun","Maria","", "","Geri"},
  133.                    {"", "","","","Marin","", "Plamen",""}
  134.             };
  135.  
  136.             for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
  137.             {
  138.                 Console.Write("Red {0}: ", i);
  139.                 for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
  140.                 {
  141.                     Console.Write(" {0}", positionsOfTheStudents[i, j]);
  142.                 }
  143.                 Console.WriteLine();
  144.             }
  145.  
  146.             int[][] jaggedArray;
  147.             jaggedArray = new int[2][];
  148.             jaggedArray[0] = new int[8];
  149.             jaggedArray[1] = new int[5];
  150.  
  151. /*
  152.             string temp = "";
  153.             for (i = 0; i < 10; i++)
  154.             {
  155.                 temp += "*"; // "*";
  156.             }
  157.  
  158.             Console.WriteLine(temp);
  159.  
  160.             for (i = 0; i < 14; i++)
  161.             {
  162.                 temp += "@"; // "*";
  163.             }
  164.  
  165.             Console.WriteLine(temp);
  166. */
  167.             Console.WriteLine(createString(2));
  168.             Console.WriteLine(createString(20, "@"));
  169.             Console.WriteLine(createString());
  170.  
  171.             Console.WriteLine(createString(10, "^", "Rayna", "Mimi"));
  172.  
  173.             Console.WriteLine(factorial(2));
  174.         }
  175.  
  176.         static string createString(int strLength, string str = "*", params string[] par)
  177.         {
  178.             string temp = "";
  179.             for (int i = 0; i < strLength; i++)
  180.             {
  181.                 temp += str;
  182.             }
  183.  
  184.             foreach (string item in par)
  185.             {
  186.                 Console.WriteLine(item);
  187.             }
  188.  
  189.             return temp;
  190.         }
  191.  
  192.         static string createString() {
  193.             return "Hhahaah";
  194.         }
  195.  
  196.         static int factorial(int n)
  197.         {
  198.             if (n == 0) return 1;
  199.             return factorial(n - 1) * n;
  200.         }
  201.  
  202.     }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement