Q:

Write a C# Sharp program to check a given array of integers and return true if the array contains 10 or 20 twice. The length of the array will be 0, 1, or 2

0

Write a C# Sharp program to check a given array of integers and return true if the array contains 10 or 20 twice. The length of the array will be 0, 1, or 2

Sample Output:

False
True
True
False

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {
          
          Console.WriteLine(test(new[] { 12, 20 })); 
          Console.WriteLine(test(new[] { 20, 20 })); 
          Console.WriteLine(test(new[] { 10, 10 }));
          Console.WriteLine(test(new[] { 10 })); 
          
        }
        
       public static bool test(int[] nums)
          {
            return nums.Length == 2
                && ((nums[0] == 10 && nums[1] == 10)
                     || (nums[0] == 20 && nums[1] == 20));
          } 
   }
}


need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now