Skip to content

Commit 3c51010

Browse files
authored
Update variables.md
1 parent 6ec52fb commit 3c51010

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lessons/variables.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Variables are arguably the most important thing in programming any language. Var
1212
This is what the variable stores, some examples are:
1313
* `String` - Stores text, such as "Hello". String values are surrounded by double quotes.
1414
* `int` - stores integers (whole numbers), without decimals, such as 123 or -123.
15-
* `double` - stores floating point numbers, with decimals, like 19.99 or -3.14159265 (for people with experience, we will not be using `float` in our code).
15+
* `double` - stores floating point numbers, with decimals, like 19.99 or -3.14159265. Double values end with `d`. (for people with experience, we will not be using `float` in our code).
1616
* `char` - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
1717
* `boolean` - stores values with two states: `true` or `false`
1818

@@ -42,7 +42,7 @@ System.out.println(message);
4242
The code above will print the value of the variable `message` which in this case is `"Hello World"`.
4343

4444
```java
45-
double pi = 3.14159265;
45+
double pi = 3.14159265d;
4646
System.out.println(pi); // Prints 3.14159265
4747
```
4848

@@ -68,4 +68,21 @@ System.out.println(number); // Prints 41
6868

6969
number = 67; // Changes number to 67
7070
System.out.println(number); // Prints 67
71-
```
71+
```
72+
### Using Variables
73+
Variables are useful in that they act as their value, here's some examples of variables being used.
74+
```java
75+
double x = 0.4d + 12.1d; // After the =, we can put any expression that gives us a value, for example, math operations
76+
77+
double y = 2.4d + 0.1d;
78+
79+
double result = x + y; // 12.5 + 2.5
80+
System.out.println(result); // Prints 15
81+
```
82+
```java
83+
double x = 1;
84+
x = x + 1;
85+
86+
System.out.println(x); // Prints 2
87+
```
88+
In our next lesson we'll look at functions and how they are useful.

0 commit comments

Comments
 (0)