使用matlab编写请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。 注:星期几的英文为Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
时间: 2023-06-09 21:03:09 浏览: 254
您好,感谢您的提问。以下是使用Matlab编写的判断星期几的程序:
```
dayStr = input('请输入星期几的第一个字母:', 's');
switch dayStr(1)
case 'M'
fprintf('星期一\n');
case 'T'
if length(dayStr) >= 2 && dayStr(2) == 'u'
fprintf('星期二\n');
elseif length(dayStr) >= 3 && dayStr(2) == 'h' && dayStr(3) == 'u'
fprintf('星期四\n');
else
fprintf('输入有误\n');
end
case 'W'
fprintf('星期三\n');
case 'F'
fprintf('星期五\n');
case 'S'
if length(dayStr) >= 2 && dayStr(2) == 'a'
fprintf('星期六\n');
elseif length(dayStr) >= 3 && dayStr(2) == 'u' && dayStr(3) == 'n'
fprintf('星期日\n');
else
fprintf('输入有误\n');
end
otherwise
fprintf('输入有误\n');
end
```
该程序使用了switch语句来根据第一个字母判断星期几,如果第一个字母无法判断,则根据第二个字母来判断(仅限于“T”开头的星期二和星期四以及“S”开头的星期六和星期日)。程序会提示您输入星期几的第一个字母,然后输出对应的星期几。希望对您有帮助。
阅读全文
相关推荐


















