Write a C# Sharp program to create a new string taking the first character from a given string and the last character from another given string. If the length of any given string is 0, use '#' as its missing character
- برمجة سي شارب
- برمجة
- 2021-05-17
- MarwaMohammed
الأجوبة
using System;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(test("Hello", "Hi"));
Console.WriteLine(test("Python", "PHP"));
Console.WriteLine(test("JS", "JS"));
Console.WriteLine(test("Csharp", ""));
Console.ReadLine();
}
public static string test(string s1, string s2)
{
string lastChars = String.Empty;
if (s1.Length > 0)
{
lastChars += s1.Substring(0, 1);
}
else
{
lastChars += "#";
}
if (s2.Length > 0)
{
lastChars += s2.Substring(s2.Length - 1);
}
else
{
lastChars += "#";
}
return lastChars;
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
