(ε-faster than slow motion)
Arrays provide a way of holding more than one value with the same variable name
If we know the size but not the content of the array
If we know the content of the array
initialize_index;
while
( logical_expression ){
do something;
change_index_value;
}
for
(initialize_index; logical_expression; change_index_value){
do something;
}
for
(TYPE
element_name: array_name ){
do something with element_name;
}
and Strings
Accesing the character at position i
:
Accesing the character at position i
:
Use binary_number.charAt(i)
in a loop to check if the character at position i
is a 0 or a 1
We can use loops for counting
Count the numbers from 1 to 100 using a while loop
Using a for loop
Let's use a loop to check if a number n
is prime
Test: n
divisible ONLY by n
and 1
Procedure: Check if any number from 0
to n-1
divides n
Checking if a number is prime with a while loop
Checking if a number is prime with a for loop
How we do determine the prime numbers between n= 1
and n=100
Realising when you can break up a task into sub-tasks
Methods are defined by their input and their output
You can also think of them as mathematical functions
Methods are defined by their input and their output
You can also think of them as mathematical functions
Methods are defined by their input and their output
Methods in Java are defined by:
Methods in Java are defined by:
int x
) return x*x;
)Methods in Java are defined by:
int x, int y
) return x*x;
)Methods in Java are defined by:
String[] args
) void
)Methods in Java are defined by:
int n
) return answer;
)/