#### Transcripts

1. Introduction: programming is the future. If you know programming, you can get great job with the lots of benefits. These days, firms are desperate to find programmers, so they are able to offer you plenty of benefits. By the way, why is that? If learning programming have so many benefits, why aren't there more people learning it? Well, it is not easy. Lots of people give up, but you can definitely learn programming like everything. It is all about practice. This girl's will teach you the basics like what is variable? How to use if condition, what is array loop function? And as in bonus, I will show you how object oriented programming works. Also in this curse are plenty of applications on which you can practice. So do you want to learn programming?
2. What is programming: Waters Program program is a set of instructions, so programming is basically telling computer what to do. But you can communicate only by instructions that computer can perform. It's same way. As with humans, you have instructions. So if someone tells you to shut up, you know what to do. Or if someone tells you to raise your right hand, you can do that. But if someone tells you to drive a car to Mars, you cannot perform that operation. Computer worries the same way only the instructions looks like this store. Something in memory at 10 and 15 is 15 bigger and zero thing the top left pixel to read. Now you might think, OK, that's great. Bad. How do we create a useful application with these limited instructions? Well, you bragged the application to set of instructions. Think of it this way. If you get lost and ask for route, you will receive a set off instructions like go one mile, turn left, then take the second right and you can miss it. But if someone tells you yeah, it's two miles dead way you will get lost. Same way with computer. You cannot tell computer. Hey, dude, is that? No, you have to tell him. Bring this on a screen. Take that from user, multiply this and debt and print the result. So the important thing from this lesson is that you are telling computer what to do. Set bicep using instructions that computer can't perform.
3. HelloWorld: I have a rare opened net beans and if you want New Java application, just did this file button and then new project than net beans ask you what type of applications you want. In this curse, we use Java so in categories should be Java and in project should be job application and then it next. Now we choose name of our application. I will just ride Hello world and it finished. Obviously you can choose your own name that in this application I will show you how you can print hell World. So that's why I choosed his name. Now I want you to dry our attention to this main function. This is what computer starts to execute when you run your application. So here's where you write instructions and the first instruction that I will show you his instruction that there's computer to bring something on screen. I will just write system dot out dot Brent line and then inside these Prentice's I will write what I want to bring so quote and inside them Hello world. Another thing you need to know is that in Java we write Simic alone at the end off each line like this. Brent Al Anna means bring line. So after printing hello, world comforter ends the line. And then if I want to bring something again, it is printed under this line. So let's run the application. We do that by this kind of play button, I guess. And here is Hello, world ridden on screen. That's all I have for this lecture and I will see you next time.
4. What is Variable: So what is variable variable is basically a space in memory where you can store something and you can access it by name. And why is it called variable? Well, you can change its value. How many times you want. The variable will still live somewhere in memory, and you can still excess it by its name. Only thing that changes is its value. Variables are in every program and in every application that you use, so it is important to know how to use them. So, to sum things up, variables gives you the power to store data in computer memory and easily excess it or change the data by name, and you can choose the name. It's only up to you. Other important thing is that D variable have something called data type. This thing defines what values can be stored in this variable, for example, numbers or characters, and I will talk more about it in the next lecture
5. Data Types: the type of variable is defined when you create new variable. Mostly, you want to start something basic, like number or character or string, so you can tell the computer A. I want a memory for some number, and I want to excess it by this name. It is actually much simply, or Dennett sounds that Why do we have to define type of variable to computer? Everything is just zeros and ones, so he doesn't care. Rotary store number or character? Yes, computer doesn't care. This feature is added for US programmers because if you write some complex application, you need hundreds of variables and there is no type. After a while, you will get lost and do something like multiply a string by number instead of multiplying two numbers and your application would crash. So we need data taps that not because of computer. In the beginning, the thing that variable can be set on Lee to one data type. It's kind of a pain in the yes, but as you get more advanced, you will appreciate this feature the most years. Data types are indeed er and killed you right in, and it can counting numbers from minds to billions in something to to billions. But this number can't have debts. Um, appoint similar data type is short, which can contain numbers without decimal point, but smaller. It is from about minus 30,002 plus 30,000 that mostly you will you've seen dangerous instead of short. I just want you to know that something like this exists. If you want to soar really big numbers, you can use long data type. This allows you to store numbers that have 18 zeros, and that's a lot. If you need store decimal numbers, you can use double date attacked. Here, you can store numbers like 10.8 or minus three. Another data tap you will definitely use is character and killed the right car and can contain one character like a or dot or space. And another data type is string. It can contain, for example, hello world or James or any other string. Another data type. It's important, mostly in conditions. It is bullying, and it can be set to true or false, and that's it. If you have any questions, just ask, and I will see you next time
6. CODE Variables: Finally, let's look how we can create a variable. We create variable by writing the data type and behind it the writing name of Are Variable . So let's say that we want number. So we right end in, like, indeed er and name. Let's say our number now we have space in memory for some number. We finished by writing semicolon at the end of line. This set is Gold Declaration. We do this only one time when we want to assign value. Be right, only the name of our variable. Then we can said the variable to some value. Let's say zero. So our number equals 20 and semi cone. We have to write Sema Cohen at the end of each line. Now we can bring the number. So do you remember how we printed Hello world? We will do the same, but this time we won't bring hello world that we bring our number. Now let's try to change the value off our number. Since it is in teacher, we can start only numbers. So let's say our number equals Stan and let's bring the variable again. I will just get up. It pays de lying above and Rhonda program. As you can see the river ride it zero by 10. Now let's see what will happen if we said this very ever to string. So, for example, are variable equals ABC. Oh, do you see this red underline? That means something is wrong and we cannot said the variable to string because this very ever can contain only in teachers and net beans is smart enough to tell us that. And if you have are over the line like this, you will see error. String cannot be converted to in teacher. And if I try to run this program, Net beans tells me there some errors, so we have to change that to, let's say, two plus two. If you want to start decimal numbers, we use double data type, so double decimal number and semi corn than initialized decimal number two tend that 15 and everything is all right. So let's try to print this variable. We're on our program, and as you can see, there is standout 15 printed. Also, we can save space by declaring and initializing the variable and one line like this. And since I don't want to make this video boring. I will go through the rest a bit faster. So let's create a car, variable my character and initialize it to see when we are riding character, we use single quote and inside we write our character. Another data type is string, so we are declaring same way. But this time we are using string keyword and string value is surrounded. Bike walked like this. Also, we can set very able to result of some operation. For example, if I declare new in teacher very ever and then said this variable to result of 10 plus 15 or I can set it to 10 minus other variable, I suggest you play with this and try what happens if you had two strings or string and character or string an integer, try what you can do and what you cannot do. If you have any questions, just ask them and I will soon except
7. Assignment Operation: when you want assign value to vary ember, you have multiple choice. You can set it to value like 10 or ABC. You can set it to variables value, like my variable equals out of variable off the same data type. You can set it to result of some operation or expression if you want, and in this expression you can use out of variables. So, for example, very ever equals my number plus 10 or plus not variable or other operations like miners. Divide, multiply modelo. Also, we can use some advance assignment operation, and these are used if you want to add to value of some variable, other value. So let's say we create variable and set it to one. Then we want to add 10 to value of this variable, and we can do that by writing variable equals variable plus dead four. We can just write plus equal 10. And these two instructions do the same thing, which is at 10 to value of variable and then Sordi result into variable. But I don't recommend using this at the beginning because at the beginning it can get confusing. So I recommend for you to use the first choice. So that's all there is to it. I suggest you play with that and I will see you next time.
8. Logical Operators 1: you probably know smaller than operator. If something is smaller than something else, it is true. Otherwise falls. These kind of operators are heavily used in every application. The expression could look like this brewery invariable is set to the result off, then is smaller than free. As you probably figure out, this variable will have value of force. Also, you can use the expression like if some variable is greater than zero. If values starting this variable is greater than zero, it is true. Otherwise falls. Other operators like this are the bigger than or bigger than or equal to or smaller than or equal to. Other useful operator is these equal operator, since we are using equal sand for assignment, if we want to check weathered value is equal. Rewrite two equal sides like this, so then it's equal to 12 will result into force, and 10 is equal to 10 will result into true. Once again, you can use variables as an operates, so instead of 10 you can have some variable instead of 12. You can have out a very ever and check whether they are containing same value. Other heavily used operator is not equal operator, which is defined as exclamation mark and equal sign like this. So 10 is not equal to 12 is true, and 10 is not equal to 10 is false. And once again you can use variables instead of a prince. I suggest you play with there's a bit and I will see you at the next video.
9. Logical Operators 2: logical expression returns bullion value, so the result is either true or false. It takes some operations and these up Arends have to be also bullion value. So true or false, first thing we can do is negation, which is these exclamation mark and what it does well, it flips the value so negation of true is false and negation of false is true. I open and makes sense. Other logical operator is sent. This operator returns true. If both arguments are true under rise in returns false. So for example, bull result equals two true and false. We basically store false to result variable. Another useful logical operator is or there's operator returns false. If both arguments are false, otherwise it returns true. So for example, true or false will result into true. These operators are extremely helpful in conditions. As you will see later on, you can combined these into more complex expressions like true or false and true that I recommend doing this when you get more advanced at the beginning just great new boolean variable and set it to the result of false and true and then do true or are variable With that being said, you can play with this bit and Duyvil See you next time
10. If condition: if condition is essential Without it, we would not be able to decide and make smart application. So it looks like this. We got the if key vert, then we have parentheses, and inside them is condition behind this. Parentheses are braces. Where are the instructions we want to execute? And these instructions are executed only if the condition is true. If it is false computer counting use by instruction under braces. As a condition, you can have some born in value, so falls are true or boolean variable. Also, you can write their expression that results into bullion value. So, for example, then is less than 20 or for example, 10 is less than 20 and 20 is bigger than Ferdi. This condition would result into false, so instruction embraces will not be executed. Also, you can use else if it looks the same as regular. If Onley this side only this time it have to be placed right under if or another else If conditions and the code embraces is executed on Lee when every condition bath was not mad. The last instruction this else this instruction have no condition. It has only braces. It has to be placed under some if or else if condition at and executes decode when all the if and else if conditions above. We're not mad. I think you will understand it better on an example. So let me show you.
11. CODE IF Condition: I prepared some meth conditions for you to see how computer executes them. So let's get started. I gather your two variables. One is guilt, bigger number, and it is initialized to 10 other one a smaller number and it is initialized to one. So let's see how the first F condition looks like the killed inside. This condition will be executed if bigger number is not equal to smaller number. Since it is not, computer will do all the instructions inside of these braces. In this case, comparative Prince 10 is not equal to one, and then it continues with next line. So let's also move on to second if condition. If bigger number is equal, it's a smaller number. Computer print Stan is equal to one, but then is not equal to one. So computer skips whatever is in these braces and runs into this else and sends the condition above. It wasn't met. It brings else bath took place. Let's look at third example sends bigger number is bigger than smaller number. This condition will be true that the second condition is also true because then is not equal to one. So what computer does he doesn't even get to the second condition because the 1st 1 is true . So he that's instructions inside these braces. So he prints stand, is bigger than one and then skip all the else. If conditions and else condition under the fourth condition looks similar about this time, it is split it into two. So first born is this one, and the 2nd 1 is this one. It is the same as previous case Onley. This time there is whole new, if not else. If so, computer executes the first condition. It is true, so he prints. Stand is bigger than one and then he moves on to next line. It won't skip anything because there is no else if nor else condition. So he checks whether bigger number is not equal to smaller number and since it iss it, brains stand is not equal to one, and it's gives the else statement. So computer gets to fifth condition and starts the check. Bigger number is smaller or equal to smaller number. That is not true, so decoding these braces will not be executed. Then computer moves on and checks. Whether is bigger number equal to smaller number. It is not so once again, it will not execute gold inside these braces and it moves on to third condition. Bigger number is not equal to smaller number. That is true. So computer, the brain Stan is not equal to one at it skips the else if condition under. So even though 10 is bigger and one computer will not bring that, let's move to assess condition then is not smaller than one, so this will not be executed then is not equal to one. So this also will not be executed, but since then is not equal. One is true. This land will be executed. Let's look at more complex conditions if then is bigger than one, and tennis smaller than one is true. These two lines will be executed, so 10 is bigger than one. That's right, but then is not smaller than one. And since true and false will result into force, the code in these braces will not be executed. But the second condition will take place since the first part. It's true, and the second part, it's also because there is this negation. So if I read this condition as a human, it would sound like 10 is bigger than one and 10 is not smaller than one. And obviously that is true. So computer executes these two lines, and it skips over the Celts statement and the last war buff, if statement iss similar. So I will read this 1st 1 as a human, then is not bigger than one or 10 is smaller than one. As you probably figure out, we get force or force. So this whole condition we're resulting to false okay, computer continues with this else. If statement so then is bigger than one or tennis smaller than one and we get true or false , so this whole condition will result into true. So computer executes instructions inside of these braces and once against gives over this else statement, and that's it. If you don't understand something, just ask, and I will soon except
12. Switch: a switch statement allows a variable to be tested for equality against the list of values each values go. The case and the variable being switched on is checked. For each switch case, you can have any number of case statements within a switch. Each case is fold by the value to be compared to and the Cullen the constant expression for case must be the same data type as the variable in the switch. And it must be a constant Wendy variable. Being switched on is equal to a case. The statements following that case will execute until a break statement is reached. When a break statement was reached, we jumped out off the switch and continue with another statement. And other important thing is that not every case needs to contain a break. If no break appears, we continue with next gays. A switch statement can have a non optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case. Also did the fourth case IHS same as else statement in the if condition and that's pretty much it. So I will see you at the next video
13. CODE Switch: I prepared some switch statements, so let's go through them. But first I got here in Teacher Variable called Switched in and Out of Variable called Result. So Computer runs into the first sweet statement and see that he will be comparing. Switched in. So he goes through every case, starting with zero. So it's five equal to zero. No. So he skips these two lines. Notice that behind zero is not semicolon, but there is a comb. So Campell two moves on to next case, and since five is not equal to two, it moves to next case. And since five is equal to five, it says the result to 10 times wife and break out of this rich so computer continues by printing. Result is 50. Let's look at the 2nd 3 statement. It is the same as before. About this time, I forgot to put break under days line. So what? Computer Douse computer just continues with next case, and since the next case is default, computer will also execute this line. So when we print the result, it will be 10. The furred and last switch is switching on Curreri, a ble gold operation. This variable is initialized to plus So computer compared the variable operation with first case and since plus is equal to Plus we said the result to 10 past five and break out of this switch. I hope you understand it. We just take the variable and compare it to a few cases. Also, you can revive these switch conditions to if conditions that does the same and that's pretty much it. So if you have any questions, just ask them and I will see you next time.
14. What is Array ?: What is a Ray Beret is basically collection off variables off the same type in one. Let's say we want to start the first names off our friends. We could have, let's say, 10 variables off type string and it each of them. We have one name about better way to starting names of our 10 friends is Array. Array is declared like this, so we have type. But then there are squared brackets and then name. And if we want to initialize this collection with names, we write braces and separated the names with comma Pretty good, right? And the best thing is we can get to each name by its index that the weird thing is, we start indexing from zero. So these are indexes so far names, and when we want to excess some name in the ray, we just ride the name of our array than square brackets and inside we right index off the name we want to excess. And if you want to change value at some index, we ride once again. Name square brackets and index equals to some new name, so it's same as very imbues. Also, every array have a property killed length, and that is just number of elements in the ray. So in our example number of names, we can access this property by name of our variable that length, and that's pretty much it. If you have any questions, just ask, and I will see you next time.
15. CODE Array: I gather you're a cold Ages They're five numbers. Let's start by branding the first number. Remember, we are indexing from zero. So if you want to accept the first number me ride zero into squared brackets out of the thing, we can do this Store some number two variable This time I store number on index to and then I print e variable. So you believe me? This works at the thing we can do is we can set element on some index two different value. So I said the element on index to to whatever already ists on index two plus one. So 2 30 once again I friend that. So you believe me. Last thing you can do is to excess the length off Ray, and we do it by ages dot length underneath. I did the same, but this time I use string Gray. The important thing is that you can excess only indexes in certain range exactly in rate from zero to the length of ray minus one. If I try to access the name on the next minus one, I will get some error. I suggest you play with there's a bit and if you have any questions, just ask and I will see you next time
16. What is loop : As the name suggests, Loop repeats the same set of instructions over and over until receiving the order to stop, and the order to stop is mostly defined by some condition. So we look while this condition is true and when it is false, we move on to instructions under the loop. Also, we can get out of loot by writing break statement inside this cycle. Remember how we used break in switch? This is pretty much the same. And do remember a race Loops are off the news. If we want to go through some collection of data like array, we got free types of cycles for a while and do while for cycle is used when we know how many times we want to loot. So, for example, if I know that I have 10 names in the ray, I will use four cycle while cycle loops while some condition is true. So while cycle is used, when you are waiting for something and you don't know when it will happen, so four is used when he know how many times you want to look while is used when he don't know how many times you want to lose. I will show you examples in next lecture. The last cycle is do a while. This one is pretty much the same as while about this time, instructions in loop are executed at least once. I know this might sound confusing, So let me show you some examples and hopefully that clear things up.
17. CODE For: before I talk about four cycle let me show you operation that is used them pretty much every four cycle. This operation is got in commenting. So it looks like this. I have your variable initialized to one and online under I incremento this variable and in commending means adding one to current value of very ever. So it is the same as writing. Temp is equal to 10th bus one. You can also decry Ament and that is what this line does, Deke. Amending is just like doing temp is equal to tempt minus one. With that cleared up, let's look at cycles. Almost every four cycle looks like this. First we declare and initialized some variable. We call this variable counter. Mostly the name of this variable is I or J. Then we have semicolon that splits the ending condition. So if this condition is false, we break out of this cycle. Then there is another semi card and last its final expression, an expression to be evaluated at the end of each Lubitsch oration. This occurs before the next evaluation of condition. Generally, it is used to update or incrementally counter variable. We put all these free things in Bren theses. And then we right into braces. What we want to do. Each interational the set of instruction inside braces are usually called body. And the thing is that when computer goes through every line in body, it does final expression and jumps back to top where he checks this condition and if it is false, he breaks out of the cycle. If it is true, he do another iteration. So this particular cycle will print. I is now zero. Then he brings I is now one than to free and four. And when I is for the final expression will increment I 25 And that means that this condition is false because five is not smaller than five. So we break out of this cycle. I hope that makes sense. We are repeating this land while I is smaller than five. The next cycle is a bit interesting and you will use that very often. So I have here array containing four names and we will use for cycle to print all the names . I hope you remember how we excess almonds in the ray and how we get the count of elements in the Ray because we were used this. So I create new variable I and initialize it to zero since the first name is that in the zero, the ending condition is I smother than number of names because last name is that index number of names minus one. And as final expression I income and I and that's it, then I just bring the name and index And not a good thing to know is that all of these free expressions in parentheses are optional. What that means is they don't have to be there. As you can see, in this third cycle, I removed the final expression from parentheses and added to the end of body. So this cycle is same as the second cycle. Now, I just want you to know this is possible, but I don't recommend doing this. You should write four cycle like the first or 2nd 1 if you can, so that's pretty much it. And I will see you next time
18. CODE While: while sacral is mostly use when you don't know how many times it will be repeated, it can be also used when you know how many times you will repeat that it looks similar as if statement, but instead off. If there's while condition is still in parentheses and body is embraces, the only difference is that while starts on Lee, if this condition is true, if it is false, it breaks away. And each time we reach the end of body, we go straight up through this condition. And if it is true, we do every instruction in body again. So what do you think will be printed? Well, since we are incremental tempt, this condition will be false when them is equal to five, right? Because for its smaller than five. So we evaluate the body. That means we increments tempt and tempt will be five. Then we go up and see that this condition is false. So we break out of this cycle and continue with this line. Another example of while is with array. So I got your ray containing six numbers and this while loop prince all the numbers. So we initialize very ever lie I is an index. We initialize it to zero, since we are indexing from zero. And while our index is smaller than count of our numbers in the ray we Brendan number and increment our index, then we do this soul over again. While I is smaller than length off our ray. When it is bigger or equal, we break out of the cycle, and that's pretty much it. This second cycle should probably be ridden as four cycle, since we know how many elements we have in the ray. But I wanted to show you that you can use both, although I recommend using four cycle for this kind of work. If you have any questions, just ask, and I will see you next time.
19. CODE do while: do While it's pretty much the same as Weil Cycle Onley difference is that the condition is at the end so at least once the body will be executed. Do a while cycle Looks like this first is that you do keyword. Then there are braces defining the body and behind these braces is wild keyword and condition. But this time we have to write Semicon at the end of line with while that it's kind of weird but you will get used to it This time I got only one sack of four Demonstration I got your variable. I initialized to 10. Then there is this do while cycle which loops while I is smaller than 10. But I is sen So this condition is not met already. That computer doesn't know that agents evaluates in sections from top to bottom. So first he do everything in body and in this case he increments I So I is now 11. This condition is not met so we won't go up again and we continue with instruction under this cycle I got here this same cycle only this time I wrote it as a while not as do a while And this time the body will not be evaluated because the condition is not met in the beginning. So we break out of the cycle and print end off program, and that s pretty much it. I will see you next lecture.
20. What is function: What is function function is a group off instructions that takes some input and returns output. Yeah, you probably look something like this. If I take the example from Rail World, imagine that you want a coffee from Automat, so you take money, pass it to out a mat, and it gives you coffee or something similar to coffee. In this example, your money is the input, the operations that out, Madison our instructions in function, and the coffee is southward. Similarly with computer. If you have function that accepts us input, some anti jer and the past value this set as value to, let's say, variable X in the body. We do some operation. Let's say X Time X and we were turned. This as you result or as our output if you want, I will explain more how this works. In next lectures, you may notice that this function returns X squared. You can find out it's similar to Mathematica function. If you have Mathematica function, let's say F where why is equal to X squared? Why is exactly what our computer function returns and X is exactly? Would our computer function takes? If you have questions, just ask them and I will see you next time
21. CODE Functions: Let's start with data type when you write function in Java. Since it is object oriented programming language, you start with public and static keyword. Then we have returning type. That means what Well, you will this function return? It can be any date attack boring in string car. But it also can be array. And it can also be nothing because sometimes we don't want to return a value. In this case, we return in teacher value. Then we have the name of our function. This name should be telling you what function? Dusk. After that, we have so killed para meters. That is the input. Once again, you can have any data type or this parentheses can be empty. In this case, we accept one integer value and inside of this function, we excess it by name X. Remember, this variable lives only inside off this function. You cannot excess it from different function than there is the body off function. Where readers some operations in this particular function, we said, why two x time sex and then return. Why down here? I got example of ah function call. It is actually pretty simple. We create variable off function Return died in this case end and then we said its value to this function call. So we ride the name of our function and then m parentheses. We write our arguments in this example valued that will be set to X. And the cool thing is that after this girl, I can call this function again with different argument, and it will still return this argument squared. So in this case, 25 not a type of function is the function without output value. So here is example I got here public static and then white keyword. This means that this function is not returning any value, but it accepts one argument, some indeed, your value. And it brings this argument so if I want to kill this function, it would look something like this. Since there is no well put value, we don't need store the information, we just go this function. So, for example, I can kill this with temp variable. And what camp here to does is he looks at the value of variable and passed the value to this function. So in this case, he calls it with 25 another example off. How you can call this function is here where repairs the result of some Operation computer evaluates This expression finds out it's 25 said the number variable to 25. Another function I gather here is this function. It takes two in teacher numbers and it returns. Boonen value so true or false, indicating weather. The first number is bigger than these 2nd 1 so you can pass multiple arguments to function . In this example. We are passing to values and let's see how we call this function. First case is similar to the first goal since the output of this function is bullion value . We create bullion very ever and initialize it to the result off this function Call in this case false. Also other interesting thing you can do is used the output value and some condition. So, for example, if then is bigger than eight. You print end is bigger than a and that works because the output of this function is bullion value. So when camp you two runs into this, if he very way the function and finds out it is true. So he executes the instructions in these braces. Also, you can use this inside some cycle. So, for example, while them is smaller than 1000 we set them to result off them squared. So eventually we break out of this cycle, and then we bring them. And last thing I want to show you is a function without arguments. So, for example, this one, it have no output value, So it is a void. And these Bren theses are empty, so it accepts no arguments. So if you want to kill this function, huge is riding name and empty parentheses like this, and that's it. So if your questions just ask them and I will see you next time.
22. When to use functions: why use functions? The first reason is reusability. Once the function is defined, it can be used over and over and over again. You can involve the same function many times in your program, which saves you a lot of work. Also, let's say that Do you have a repeating code and you need to change something If you use functions, you changed it only ones that if you are not, you have to change in multiple times. So each time you are writing code that you already wrote somewhere else, you should use function and just go. The function whenever you need, instead of copy, pays these same coat over and over again. The second reason is abstraction. In order to use a particular function you need no these following things. You need to know the name or function. You also need to know what these function does, and you also need to know what arguments you must give to the function. Lastly, you have to know what kind of result the function returns, but notice if you just want to use the function in your program, you don't have to know how it works inside. It's sort of like driving the car. You don't need to understand every detail about the engine and wheels and stuff all you want to do. It's drive the car, so I hope you understand. Functions are great. I recommend using them a lot and I will see you next time.
23. Calculator: Okay, guys, you should be able do try to make your first application. So the first project, we will do its simple calculator. I will show you things you will need to know and also kind of guide you to solve the problem. So first thing you need to know is this you can ask user for input and you will do that by writing this line. The thing use rights is in store to variable. But even though use the rights for example 10 This function goal we're during Sten as a string so like this. And in order to do mathematical operations you need in teacher variable so and not a thing I will show you is how we can change data. Type off some value in case you want to change string value to integer value. We do this line. And do you remember how I talked about abstraction? When you are using functions notice. I don't know how this function is implemented and what did the US inside. But in order to use this function, I don't have to. All I need to know is what this function takes as arguments and wanted returns. So now you have every instruction you need to create a simple calculator. I imagine the discipline cation will work like this. You ask, user, What is the first number? Use the right something. Then you ask What is the second number? User again, right? Some number and then you bring the result off. First number plus second number First number minus second number. First time 2nd 1st divided by second and first model sickened. I suggest deposit video and try to make this app. It is okay if you get error and your application won't work, just try. And if you get sack in the next video, I will show you my solution.
24. SolutionCalculator: so the solution is not so complicated. First we bring, please enter first number and then we reading number user rights. That's what this line does. Then we got the value that use road. But we still need to convert it into a Nen teacher. And we will do that using this function. Then we ask user to write second number, and they're the same with second number. So now we have these two numbers as Annan teachers now. Oh, we need to do it's compute the results off. Plus, that is this line minus that Is this line multiplied. Is this line divide? There is this line and last operation is model. So then I just need to print these variables and that's it. If you have any questions, just ask, and I will see you next time.
25. SumOfArray: this time I wanted to make some over a so add up every number in array The in poetry is right here. I want you to use loop in this application where you add up all the numbers in array. Then you bring these some and Deva Ridge. You should already know every instruction that you will need for this application. I recommend using four loot But you can also use wild loot years how the output should look like. So here's the some off all elements in the array and here's the average value in array. So try to create this app And if you get sack, I will show you solution in the next video.
26. SolutionSumOfArray: So in order to sum up all the numbers in array, we need some variable where every story current, some off the numbers we already read. So I declare new variable called some and I initialize it to zero. And since average is just some divided by a number of elements, we don't need variable for average. So in the next set, I go through every number in array using this four loop. So here is counter variable called I. And while I is smaller than length of our ray, I said these some variable do the result off some plus number on index I also you can use this assignment operator which does the same. Then computer evaluates the final expression so he increments I After this cycle, I have some off. All the numbers soared in this variable. So oh, I need to do is spring these some and then bring the average and I count the average by dividing some with array length. And that's it. If you have any questions, just ask in. I will see you next time
27. BiggestFromTwoArrays: So let's say that as an input, I have to individual race and I want to know which one of them have the biggest number. So first you will print both of these race using for loop. You can print each number on one line, or you can print whole array on one line, and you can do that by system that out. That friend this function Onley prince whatever you pass, but it doesn't end the line. So after printing all the numbers, just go system that out that brained line without any arguments, and they will take care of the line ending. So here is example, how it works. I got here, system that out that friend, and there's an argument. I passed then and then I got here. System that out the print ISS number and I nd line by calling system out that brain line without any argument. So this will be Brent it on next line, and the output of this program can look like this. So here is first or a printed. Here's second Ray printed and then I got here. Biggest number is from First Toray and then in parentheses. I got the biggest number. So that's it. Blame this. Try to make it work. And once again, in next video, I will show you the solution.
28. SolutionBiggestFromTwoArrays: right. So here is how I print the race. I split it into two cycles because the length of these two race is not the same. So if you will try to excess number on index six in this ray, your application would crash. So here I print the first tray I print. While I is smaller than length of our first array, I am using the brain function. After this cycle, I print the end of line the second cycle. That's pretty much the same Onley this time I'm printing while I is smaller than length off second Ray. Then we get to the application, their capital of waste. You can solve this problem, but since the length of our to race is different, I choose to big, biggest number from first and then check whether it is bigger than every number in second. If it is bigger than every number in second Ray, it must be the biggest. But if it is smaller, then at least one number in the second Ray, it's not the biggest. So here's the code. I declared variable called biggest yet, and I initialize it to zero. Then I go through every number in first array. And if it is bigger than whatever it ISS in this variable, it is the biggest yet. So I said it as a value to this variable. After this cycle, I have the biggest number from first array stored in the variable biggest yet. Now I have also bullion value which indicates weather D biggest number is in first array. It is set to true because right now, the biggest number ISS in first array. But if at least one number in secondary is bigger, I said it to false. Now I go through every number in second Ray using this cycle. And if the number on index I is bigger than our biggest yet, it means that it is bigger than the biggest from first number. So I said it as the biggest yet. And I also said the Boolean variable which indicates whether the number is from first array to force because right now we know that the biggest number must be in Second Ray. After this cycle, I have the biggest number stored in biggest yet variable and I have the information whether it is in first or secondary stored in this Boolean variable So what I'm gonna do now is use these born in variable to bring the result. So if this variable is true, the number is in first array. But if it is false, that means else it must be in Second Ray. And that's it. If you have any questions, just ask, and I will see you next, Sam.
29. GuessNumber: the game. Guess number is based on randomly generated number from 0 to 100 and users ability to guess the number so the game could look like this. First, you asked how many guesses user wants. So let's say I want 10 guesses If users guest number is equal to our randomly generated number user winds and we end the game that each time use a guess, and it's number is not equal to our randomly generated number, we D command the number of guesses. And if the number of gases zero user loses, also, each time guest number is not equal to a randomly generated number. We give users a hint like this. Generated number is bigger than your number or smaller, so the guessing can look like this, I guess. 50. The number is smaller, so I guess, 25. The numbers bigger. So I guess, 37 once again number is bigger. So I guess 42 and number iss smaller. So I guess 40 and I want Teoh. Generate random numbers. You can use this function. Generate random in teacher where you pass minimum value and maximum value, and this function returns a randomly generated number somewhere in between. Also for this kind of game I recommend using while loop. So that's all there is to it. Happy programming. Cand I will see you in the next video Where? Show you my solution?
30. SolutionGuessNumber: So first is the simple part. Just ask User how many guesses he wants. That's what this land does. And using this line, I converted the input into integer variable. Then there is this while loot. So while remaining gases is greater than zero, we ask user to guess some number. We star whatever he wrote. And once again we convert it into integer variable because the generated number is in teacher and we want to compare the generated number with guest number. So if guest number is smaller, we give user a hint saying generated number is bigger And if guest number is bigger, we give user another hand saying generated number iss smaller. And here is the else statement. So if we get to this statement, it means that user gets the generated number because in order to get here, the conditions above cannot be met. So they have to be false. So guess number is not smaller than generated. Number and guest number is not bigger than generated number. And if it is not bigger nor smaller, it must be equal. Right. So we print you on and we break out of this cycle using this break statement If we didn't get to this else condition, we stay inside the cycle and determent remaining gases and then we go straight up to this ending condition. And if it is false, that means remaining guesses is equal to zero. We break out of this cycle otherwise we let the user guess again. So eventually we get out of this while loot. And we get to this if condition. And if remaining guesses is equal to zero user lost, you might think Why is there discontinuation? Since if we get out of the cycle, user had to lose because this condition is false. When remaining guesses is equal to zero, Well, you are right. But we also get here if user wins. Because here we have the break statement. So without this condition, we would bring you lost. Even if the user one. I hope you understand it. And I will see you next time.