0% found this document useful (0 votes)
4 views

ClassesExercise

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ClassesExercise

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Randomize words

using System;
using System.Linq;
using System.Collections.Generic;
namespace clasesss
{
class Program
{
static void Main(string[] args)
{
string[] input = Console.ReadLine().Split().ToArray();
Random randomNum = new Random();

for(int i = 0; i< input.Length; i++)


{
int place = randomNum.Next(0,input.Length);

string position1 = input[place];


string position2 = input[i];

input[place] = position2;
input[i] = position1;
}
foreach(string word in input)
{
Console.WriteLine(word);
}
}
}
}

Days of week
using System;
using System.Linq;
using System.Collections.Generic;
namespace DayOfWeek
{
class Program
{
static void Main(string[] args)
{
string dateString = Console.ReadLine();
DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy", null);
Console.WriteLine(date.DayOfWeek);
}
}
}

Factorial
using System;
using System.Numerics;

namespace Factorial
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
BigInteger result = Factorial(n);
Console.WriteLine(result);
}

static BigInteger Factorial(int n)


{
BigInteger result = 1;
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
}
}

Rectangle class
using System;

class Rectangle
{
public int Width { get; set; }
public int Height { get; set; }
public string Color { get; set; }
public Rectangle(int width, int height, string color)
{
Width = width;
Height = height;
Color = color;
}

public int CalculateArea()


{
return Width * Height;
}
}

class Program
{
static void Main(string[] args)
{
int width = int.Parse(Console.ReadLine());
int height = int.Parse(Console.ReadLine());
string color = Console.ReadLine();

Rectangle rectangle = new Rectangle(width, height, color);


int area = rectangle.CalculateArea();

Console.WriteLine($"Rect({rectangle.Width}, {rectangle.Height}, {rectangle.Color}) has


area {area}.");
}
}

You might also like