first commit
This commit is contained in:
39
Semester 1/Programming 1/Week 10/Spec Test Nodes
Normal file
39
Semester 1/Programming 1/Week 10/Spec Test Nodes
Normal file
@@ -0,0 +1,39 @@
|
||||
sum = 0, i = 2
|
||||
1: sum = 2
|
||||
sum = 2, i = 4
|
||||
2: sum = 6
|
||||
sum = 6, i = 6
|
||||
3: sum = 12
|
||||
sum = 12, i = 8
|
||||
4: sum = 20
|
||||
sum = 20, i = 10
|
||||
5: i => 9, STOP
|
||||
returns 20
|
||||
|
||||
sum = 0, k = 50
|
||||
1: sum = 50
|
||||
sum = 50, k = 5
|
||||
2: sum = 55
|
||||
sum = 55, k = 0
|
||||
3: k < 0, STOP
|
||||
returns 55
|
||||
|
||||
sum = 10, p = 15
|
||||
1: p > 12, STOP
|
||||
returns 10
|
||||
|
||||
j = 1, increment 1, stop at 3
|
||||
k = 1, increment 1, stop at less than 3
|
||||
1: 1 1
|
||||
2: 1 2
|
||||
3: 2 1
|
||||
4: 2 2
|
||||
5: 3 1
|
||||
6: 3 2
|
||||
|
||||
j = 1, increment 2, stop at 3.
|
||||
k = 5, decrement 1, stop at more than 3.
|
||||
1: 1 5
|
||||
2: 1 4
|
||||
3: 3 5
|
||||
4: 3 4
|
50
Semester 1/Programming 1/Week 10/Week 10 Programming 1.md
Normal file
50
Semester 1/Programming 1/Week 10/Week 10 Programming 1.md
Normal file
@@ -0,0 +1,50 @@
|
||||
## Lecture 2 (13:00)
|
||||
|
||||
- Remember to use `string1.equals(string2)` rather than `string1 == string2`, as the former may not be accurate.
|
||||
|
||||
### For Loop Cont.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
```java
|
||||
int sum = 0;
|
||||
for( int i = 0; i < animalCount.length; i++ )
|
||||
{
|
||||
sum += animalCount[i];
|
||||
}
|
||||
```
|
||||
|
||||
Loop Control:
|
||||
|
||||
- Initialisation
|
||||
- Loop Condition
|
||||
- Update
|
||||
|
||||
for the amount of times in the length of the animalCount array, add the animalCount\[i] to the sum.
|
||||
#### Example 2:
|
||||
|
||||
```java
|
||||
for( int k = 1; k < 500; k += 2)
|
||||
{
|
||||
System.out.println(k);
|
||||
}
|
||||
```
|
||||
|
||||
#### Example 3:
|
||||
|
||||
```java
|
||||
for( int i = 1; i < 4; i++ )
|
||||
{
|
||||
for( int j = i; j < 5; j++ )
|
||||
{
|
||||
System.out.println( i * j + "\t" );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
i = 1, j = 1, 2, 3 ,4 | 1, 2, 3, 4
|
||||
i = 2, j = 1, 2, 3, 4 | 2, 4, 6, 8
|
||||
i = 3, j = 1, 2, 3, 4 | 3, 6, 9, 12
|
||||
|
||||
- \\t represents a TAB character.
|
||||
|
Reference in New Issue
Block a user