Visual C# exercise problems 5a and 5b nttps://ngcengage.com/static/nb/u.. Bookma
ID: 3755717 • Letter: V
Question
Visual C# exercise problems 5a and 5b
Explanation / Answer
5a)
using System;
public class CheckMonth
{
public static void Main()
{
int month = Convert.ToInt32(Console.ReadLine());
if(month >= 1 && month <= 12) {
Console.WriteLine("{0} is a valid month", month);
}
else {
Console.WriteLine("{0} is not a valid month", month);
}
}
}
5b)
using System;
public class CheckMonth2
{
public static void Main()
{
int[] Months = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month = Convert.ToInt32(Console.ReadLine());
if(month >= 1 && month <= 12) {
int day = Convert.ToInt32(Console.ReadLine());
if(day >= 1 && day <= Months[month-1])
Console.WriteLine("{0} and {1} is valid", month, day);
else
Console.WriteLine("{0} is invalid", day);
}
else {
Console.WriteLine("{0} is invalid", month);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.