![]() Same example in Java would be if you declare variable of type int and you try to store number “10.000” in it. What would happen is that you would spill a quarter of milk since that cup cannot store that amount. Now let’ say on top of that quarter you try to pour another half a liter of milk. You take that cup out and pour a quarter of liter milk in it, so far so good. Q: Can you give me an example of what happens if I do not use “right size” of variable?Ī: Sure, let’s say you have a half a liter cup in your cupboard. By size, I mean to choose variable that can store whole value inside it. Q: Do I need to be aware of some traps with variable?Ī: Traps not exactly but what you should be aware of when you are dealing with variables is to be very careful to use right type and size of variable for the value you need to store. Of course, there are many other types of variables that belong to three above listed categories. ![]() – Variables that deal with logic: boolean – Variables that store characters: char and String – Variables that store numbers: short, int, float and double ![]() Q: What kind of basic variables do exist in Java programming language?Ī: There are three basic categories of variables based on what type of value they can store. Think of them like different size of cups in your cupboard ( cup – small reserved chunk of memory or variable, cupboard – available memory to store all those different cups) If you have any questions please leave a comment and I will answer it as quickly as possible.Ī: Variables are simply reserved places of memory with a predefined size based on variable type. I hope that clears how forloop works, how you declare it and what it does. K = 20 -> is k smaller than 20 -> k is not smaller than 20 -> loop ends. K = 19 -> is k smaller than 20 -> if yes increment k + 1 and print “You are the best”. K = 1 -> is k smaller that 20 -> if yes increment k + 1 and print “You are the best”. That way is quite a lot of work when it comes outputting that many times of the same String.įor(int k = 0 k is k smaller than 20 -> if yes increment k + 1 and print “You are the best”. In this part we will take a closer look at forloop, int next parts come in detail view of whileand ifloops.Ī traditional way to print 20 times “You are the best” would be:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |