‫Hello my friends, and welcome to coding Exercise number four.
‫Right.
‫A program to count the letters, spaces, numbers and other characters of an input string.
‫Please post the video and think about how to get a string from the user and count the spaces, letters,
‫numbers and other characters of this string.
‫Okay, so I help you solve it.
‫Well, let's start by getting the the string from the user scanner scan or SW one equal to new scanner
‫system dot n and don't miss to add this import java to the scanner in order to solve the scanner error.
‫Now let's store the get that input into a string input string variable equal as one dot next line in
‫order to get.
‫The next string from the scanner we use next line or next in order to get the input string from the
‫scanner.
‫Now I will create a method here called count.
‫Account, letters, characters and so on.
‫I will limit as count.
‫It will be good.
‫Public static void.
‫Count.
‫It took into the parameter string.
‫X.
‫So.
‫I need to pass this string to this method by calling this method, and I will pass the input string.
‫Okay.
‫It's very simple.
‫This count discount method will operate to tell me how many characters, how many digits, how many
‫spaces, how many letters are in this?
‫String called X.
‫I will create a car array.
‫I will name it as c h x to car array because I need to examine every as every single character inside
‫the string.
‫So I transformed this string into an array of characters now and letter equal to zero.
‫Space equal to zero.
‫Numbers equal to zero and others equal to zero.
‫These are the initialization of the letter number, the space number, the numbers, and the others.
‫We start by loop.
‫Since we have an array of characters, we need to examine every character inside this array of characters.
‫I start by int i.
‫Equal to zero i.
‫Less than x dot length and I plus plus.
‫Then we check for if that character here.
‫If the character dot is letter, we can use the character.
‫Here the character class and we use is letter to check if it is a letter where at c h of index.
‫I because I'm using a loop so I can use the index I which is start from zero until reaching x dot length.
‫So c h I then I will increase letter variable by one oc.
‫Then.
‫In order to use.
‫Since we have many decisions we use.
‫LCF So many cases we use LCF.
‫Again, I will start by the character.
‫This is the object of characters and I will check if it is a digit then I will check at c h at index
‫i.
‫If it is a digit then I will increase num by one.
‫Else.
‫If I will copy this.
‫If is the space character, then I will increase the spaces by one.
‫So space plus, plus else.
‫Then I need to make others plus plus.
‫So what I have done here, I created I have stored this string into an array of characters in order
‫to examine every letter and every character inside this string.
‫Then I have created four variables four letters, bases, numbers, and zero others.
‫And I started using a for loop that examines the this array of characters from zero to length.
‫And start checking if this character is equal to letter.
‫If it is a digit, if it is a space character or others using the if conditionals.
‫Now.
‫Outside this loop.
‫Outside this loop, I will display the results.
‫So here I need to display the results system that out the print l rn spaces.
‫Or letters.
‫How many letters?
‫I will use the letter value system that out.
‫The print numbers I will use here.
‫Spaces.
‫We use the spaces we will display.
‫How many spaces and the others like that dollar sign at the exclamation mark and we will display them
‫in the others.
‫Now let's run this program.
‫We run this with coverage.
‫And here we are.
‫We are displaying.
‫We need to enter this string.
‫So let me run.
‫Hello?
‫Let me.
‫Right.
‫Hello, my friends.
‫You.
‫Are.
‫Awesome with exclamation mark.
‫One, two, three, four, five, six, seven, eight, nine.
‫Don't miss.
‫To rate us five stars on here and I click enter.
‫It will calculate how many letters, numbers, spaces and others.
‫So.
‫Others.
‫This.
‫This comma, this exclamation mark, and this apostrophe.
‫How many numbers?
‫These are nine numbers.
‫And this is the 10th number.
‫So this is how we solve this problem, how we count the numbers, how in a string, how we count letters,
‫spaces and others in.