Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Check whether a given word is plural or not

C# Sharp Basic: Exercise-77 with Solution

Singular means only one and plural means more than one. In order to make a noun plural, it is usually only necessary to add s.

Write a C# Sharp program to check whether a given word is plural or not.

Sample Solution:

C# Sharp Code:

using System;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Is 'Exercise' is plural? " + test("Exercise"));
            Console.WriteLine("Is 'Exercises' is plural? " + test("Exercises"));
            Console.WriteLine("Is 'Books' is plural? " + test("Books"));
            Console.WriteLine("Is 'Book' is plural? " + test("Book"));
        }
        public static bool test(string word)
        {
            return word.EndsWith("s");
        }
    }
}

Sample Output:

Is 'Exercise' is plural? False
Is 'Exercises' is plural? True
Is 'Books' is plural? True
Is 'Book' is plural? False

Flowchart:

Flowchart: C# Sharp Exercises - Check whether a given word is plural or not.

Sample Solution-1:

C# Sharp Code:

using System;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Is 'Exercise' is plural? " + test("Exercise"));
            Console.WriteLine("Is 'Exercises' is plural? " + test("Exercises"));
            Console.WriteLine("Is 'Books' is plural? " + test("Books"));
            Console.WriteLine("Is 'Book' is plural? " + test("Book"));
        }
        public static bool test(string word)
        {
            int word_len = word.Length;
            return (word[word_len - 1] == 's') == true;
        }
    }
}

Sample Output:

Is 'Exercise' is plural? False
Is 'Exercises' is plural? True
Is 'Books' is plural? True
Is 'Book' is plural? False

Flowchart:

Flowchart: C# Sharp Exercises - Check whether a given word is plural or not.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program which takes a positive number and return the nth odd number.
Next: Write a C# Sharp program to find sum of squares of elements of a given array of integers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.