"Hi, Amigo."
"Hello, Eleanor Carrey."
"Just call me Ellie. There's no need to be so formal."
"OK, Ellie."
"I believe with my help you'll soon be one of the best. I have a lot of experience training rookies. Stick with me, and everything will be just fine. Well, let's get started."
"There are two major types in Java: String and int. We store strings/text in String, and integers (whole numbers) in int. To declare a new variable, you need to specify its type and name. The name cannot be the same as the names of any other variables and/or functions."
Example 1, code: | Description |
---|---|
|
A new variable s is declared. It can store text. |
|
A new variable i , is declared. It can store integers. |
"You can assign values to variables when you declare them."
Example 2, code: | Description |
---|---|
|
Variable s stores the string "Ellie" . |
|
Variable i stores the number 5. |
"To assign a new value to a variable, we use the =
sign. It is also called the 'assignment operator'. Assignment means to place into a variable a value from another variable or one computed from several variables."
Example 3, code: | Description |
---|---|
|
Variable a stores the value 5. |
|
Variable b stores the value 6. |
|
Variable c stores the value 11. |
"A variable's value can be used to compute a new value that will replace the old one."
Example 4, code: | Description |
---|---|
|
Now a equals 2 |
|
Now b equals 3 |
|
Now a equals 5 |
|
Now b equals 4 |
"You can merge strings with the +
sign:"
Example 5, code: | Description |
---|---|
|
Variable s3 stores the string "RainInSpain" |
"Sometimes, strings consisting of one or more spaces can come in handy:"
Example 6, code: | Description |
---|---|
|
text stores "My favorite movie is Route 66" |
"Let's take a look at how we display text and variables on the screen:"
Example 7, code: | |
---|---|
1 |
|
2 |
|
"By the way, Diego asked me to give you a couple of exercises:"
GO TO FULL VERSION