TAILIEUCHUNG - Java Programming for absolute beginner- P7
Java Programming for absolute beginner- P8:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | 2 25 03 8 50 AM Page 98 k 0 c c 0 2 V public static void main String args int x 0 y 0 a 0 b 0 y and x both 0 y x The expression y x results in y y and x x a and b both 0 b a The expression b a results in b b and a a 0 a c E E s k a o k a s s The output of this program is displayed in Figure . Note that the variable y is assigned the value 0 which is the value of x before it is incremented because that is the value of the postfix increment expression. On the other hand the value of the b variable is 1 which is the value of a after it is incremented. Although this type of distinction might seem trivial to you at the moment it is an important concept for you to understand. figure The PrePost application demonstrates the difference between prefix and postfix increment operations. Skipping Values In the previous section you learned about the increment operator . As you know this operator causes the operand to be incremented by one. What if you wanted to skip values while incrementing your variable in the loop You can write a loop that counts in increments of five like this for int i 5 i 100 i i 5 i The output of this program is 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100. There is a niftier way to do this described in the next section. team Line - live informative Non-cost and Genuine Please purchase PDF Split-Merge on to remove this watermark. 2 25 03 8 50 AM Page 99 99 In the Real World In the real world skipping values is useful. You might have an array that stores sets of data. For example you can write an array that stores item numbers and inventory counts called inventory . In this array inventory 0 stores the first item number and inventory 1 stores the quantity of that item in your inventory. Following this pattern all even indices store item numbers and any given odd index stores the .
đang nạp các trang xem trước