00:01
Hello, welcome to this lesson.
00:03
In this lesson, we are writing the java program that would ask the user to input a string and an integer.
00:13
And now we'll print from behind the letters of the characters in the string, the number of times that the number of times as much as the integer so for example if they type the string as as there t h e then the integer as two then it means that there is a last character in there so it would print that one two times then the h will printed two times then the t will print it two times all right so let's begin the first thing that we'll do is that we would get user to input something from the console, so we'll need to catch it and we'll need a scanner.
01:21
So we would import java.
01:28
Detail or scanner.
01:31
We would import the scanner class.
01:33
So that now we can say scanner to new scanner.
01:39
7 .in.
01:46
A first sender would need is to print on a screen and access the user to type a string.
01:54
So we'll use system.
01:57
Out.
01:58
Trink and say input a string like that.
02:11
Now when they input a string, we would sign whatever the user input is to this variable.
02:21
Str, we do that by catching what was input in a console using in dot.
02:33
Next line.
02:36
Okay, after we would again ask them to input an integer.
02:44
So print input and integer.
02:51
Now when they do, you would catch the user input and put into this variable called num using the in scanner class the method called the next int okay so now we have a string that is told in scr and the integer that is tall in the num num so this is how we're going to approach it since we would print the characters from behind we will initiate a 4 loop that an integer i that has the maximum length of the string that actually equals the index from 1 it start from 0 you would let the highest number that the i would reach be the length of the string minus 1 so for example if we have there as we've said that's an example t he then the highest value or the initial value of i would be two although the length the total characters in there is three by let it be two so that if we get to because the indus start from zero so we'll start from from two uh then come to one then come to zero right want it going to count it backwards or the next uh the i should be less than the i should be greater than zero so we make sure that it doesn't get less to the negative right then now we have i that is minus minus so actually we start i from one minus the length uh the length minus one so for example that there is tough from 3 minus 1 which is 2 then it keeps decreasing until it gets to the last one actually instead of letting it be less to be greater than 0 we will let it be greater than or equal to 0 right so that it now start from one uh the length minus 1 then it start decreasing until it gets to zero okay in that sense we can be assured that it would print from behind okay so the next that we do is that would have another full loop in there so that we can execute one thing a number of times so for example if the integer is three we can use the four loop to print three times within but now it goes one after the other at each of the characters.
06:28
So this is nj that is equal to zero.
06:33
This one is starting from zero and we'll do it a number of times.
06:39
So j that is less than the num.
06:45
Okay, so it's going to do it a number of times according to the number of the size of the integer or the integer that was put in and now j that's one will increase all right and now the only thing that we'll do is that we would print out string then we'll do charrots then we will put in the value uh the i here so what is simply that is that is going to print the character at a certain index.
07:39
So for example, the character, if we are using, for example, if you are using input, then the chart at zero would be i, char at one will be n, char at two would be p, chart at three will be you and in that other.
08:04
But this time we start from char at the length minus 1.
08:11
So this has a length 1, 2, 3, 4, 5.
08:14
It has a length of 5.
08:16
So it will start from char at 4.
08:19
Then i'll print it char at 3, char at 2, then in that order...