This is very interesting and logic building program in C#. The program will count the number of words in a given string e.g. "Hello World" has 2 words.
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace assad
{
class countWords
{
// /*
static void Main(string[] args)
{
welcomeScrean();
String str = "quick brown fox jumps over the lazy dog";
string[] arr = str.Split(' '); // split the sentence in an array of words
Console.WriteLine("\tWords List:");
Console.WriteLine("");
for ( int i = 0 ; i < arr.Length ; i++ ) {
Console.WriteLine("\t"+arr[i]);
}
Console.WriteLine("");
Console.WriteLine("\tWords Count: ");
Console.WriteLine("\t" + arr.Length); // displays the counts
int ab = Console.Read();
}
private static void welcomeScrean()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\t*******************************************************" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t** Count **" + "\n"
+ "\t** Words in String **" + "\n"
+ "\t** Program **" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t*******************************************************\n\n\n\n");
}
// */
}
}
0 comments:
Post a Comment