Section 2.6 More About Variables!
student will be able to manipulate variables to construct other variables
student will be able to understand the difference between declaration and initialization
student will be able to understand variable assignment
Integer ClassTotal = Class1 + Class2 + Class3
Here we are doing multiple things at once. We declared an Integer variable called ClassTotal and assigned the sum of Class1, Class2, and Class3 to it. This is called initialization. Initialization is when a variable is given a starting value when it is declared.
Integer Class1 = 15, Class2 = 35, Class3 = 18
Here we declare three variables altogether and initialize them. How about if we do not initialize them like we did in the earlier example? This is known as an uninitialized variable. This means that the variable currently has just some random garbage data stored in it. And if you use it without assigning it a value unexpected things can happen. So remember to always initialize or set your variables before using them.
Now we are ready to implement the problem we presented earlier.
Are you feeling ready to continue?
Yes, I’m ready!
Yay! Let’s continue.
No, I don’t feel ready.
Oh no! Take some time to reread this chapter.
You have attempted
activities on this page.