B2B-Training/Iteration/Iterations.cs
Louis 3f42af8215
All checks were successful
Tests / Unit Testing1 (push) Successful in 45s
feat: Finish FirstUpper
2023-11-02 17:17:43 +01:00

74 lines
1.5 KiB
C#

namespace Iteration;
public class Iterations
{
public static int Reverseint(int n)
{
int result = 0;
if (n > 4)
{
for (int i = 0; i <= n; i++)
{
result = result * 10 + n % 10;
n /= 10;
}
if (n == 1)
{
return result * 10 + n;
}
}
else if (n < 4)
{
for (int i = 0; i >= n; i--)
{
result = result * 10 + n % 10;
n /= 10;
}
if (n == -1)
{
return result * 10 + n;
}
}
else
{
return n;
}
return result;
}
public static bool FindSub(string s, string sub)
{
if (sub == "")
{
throw new ArgumentException("sub cannot be empty");
}
string phrase = s;
string[] word = s.Split(' ');
foreach (var mot in word)
{
if (mot == sub)
{
return true;
}
}
return false;
}
public static string FirstUpper(string s)
{
string phrase = s;
string[] word = s.Split(' ');
string result = String.Empty;
foreach (var element in word)
{
string first = element.Substring(0, 1);
result += first.ToUpper() + element.Substring(1) + " ";
}
return result.TrimEnd();
}
}