1) Printing only “Orcle” from
the following Strings?
A. Working On
Orcle Technologies.
B. Ensurity
Technology.
static void Main (string[] args)
{
string str1 = "Working on Orcle Technologies";
string str2 = "Orcle Technology";
Console.WriteLine("Printing only Ensurity in strl:{0}",
str1.Substring(11,8));
Console.WriteLine("Printing only Ensurity in str2:{0}",
str2.Substring(0, 8));
Console.ReadLine();
}
2) Print names (Ram, Ravi) as separate words from the sentence “Ram
went to meet Ravi”?
string
value = "Ram Went to meet Ravi";
Console.WriteLine("Given
String : " + value);
Console.WriteLine("Printing
Ram : " + value.Remove(3));
Console.WriteLine("Printing
Ravi : " + value.Remove(0, 17));
Console.ReadLine();
3 3)Find the index of the word “information” from sentence “The second
piece of information is the moving factor”?
Console.WriteLine("**finding
the index**");
String
testing = "The second piece of information is the moving factor";
Console.Write(testing.IndexOf("information")
+ Environment.NewLine);
Console.WriteLine(testing.Substring(testing.IndexOf("information")));
Console.ReadLine();
string sentense = "The test is conducted
by the Ravi but Ram was not corrected";
Console.WriteLine("Given sentense is:" +
sentense);
string[] words = sentense.Split(new[] { " " }, StringSplitOptions.None);
for (int i = 0; i < words.Length; i++)
{
if (words[i] == "Ram")
{
words[i] = "Ravi";
}
else if (words[i] ==
"Ravi")
{
words[i] = "Ram";
}
Console.Write(" " + words[i]);
}
Console.ReadLine();
string sentense = "The test is conducted
by the ram but Ram was not corrected";
Console.WriteLine("Given Sentense is:" +
sentense);
string[] words = sentense.Split(new[] { " " }, StringSplitOptions.None);
foreach (var word in words)
{
if (word == "Ram")
{
continue;
}
else
{
Console.Write(" " + word);
}
}
Console.ReadLine();
int[] Array = new int[] { 2, 6, 7,
3, 4, 2, 7, 9, 4 };
Array = Array.Distinct().ToArray();
foreach (int i in Array)
{
Console.Write("
" + i);
}
Console.ReadLine();
string[] str = { "Ravi", "Ram", "Raj", "Rahul", "Raheem" };
Console.WriteLine("Original array: ");
for (int i = 0; i < str.Length; i++)
{
Console.Write(str[i] + " ");
}
Console.WriteLine("\n");
str[1] = "Raj";
str[2] = "Ram";
Console.WriteLine("Modified array: ");
for (int i = 0; i < str.Length; i++)
{
Console.Write(str[i] + " ");
}
Console.ReadLine();
Console.WriteLine("Given Array : ");
string[] array = { "Ravi", "Ram", "Raj", "Rahul", "Raheem" };
foreach (var a in array)
{
Console.Write(" " + a);
}
Array.Reverse(array);
Console.WriteLine("\nReversed Array : ");
foreach (var value in array)
{
Console.Write(" " + value);
}
Console.ReadLine();
9) Print Array in ascending and descending order and
10) Print highest and lowest
value of the array {24, 22, 33, 23, 76,
87, 51}
int[] arr = new int[] { 24, 22, 33, 23, 76, 87,
51 };
Console.WriteLine("Given Array: ");
foreach (int value in arr)
{
Console.WriteLine(value + " ");
}
Console.WriteLine("Ascending order: \n");
Array.Sort(arr);
foreach (int value in arr)
{
Console.WriteLine(value + " ");
}
Console.WriteLine("Descending Order: \n");
Array.Reverse(arr);
foreach (int value in arr)
{
Console.WriteLine(value + " ");
}
Console.WriteLine("\nMax Value is: " +
arr.Max());
Console.WriteLine("\nMin Value is: " +
arr.Min());
Console.ReadLine();
No comments:
Post a Comment