String manipulation with printing of characters

The question is:
Write a script that will prompt the user to enter a word, and then print the first character in the word. For example, the output might look like this:
>> Enter a word: howdy
The word howdy starts with the letter ‘h’
How do you print the first character? I can do the:
>> word = input('Enter a word: ','s')
I do not know to display the first character.

 채택된 답변

추가 답변 (1개)

NAVNEET NAYAN
NAVNEET NAYAN 2020년 11월 17일

0 개 추천

I think the following code should work
t=input('Enter a word: ', 's');
disp(t(1));

댓글 수: 2

Liz
Liz 2020년 11월 17일
Yes I did try that before, but the question wants you to print the first letter with the quote 'The word howdy starts with the letter 'h'. I thought about maybe using fprintf, but couldn't think how to do that.
Try this and see whether it solves the purpose or not. I think it should work
t=input('Enter a word: ', 's');
char(t(1));

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

질문:

Liz
2020년 11월 17일

답변:

2020년 11월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by