Challenge done during Section 6: Loops, and the If, When, and Try/Catch Expressions.
-
Use a range to print out the numbers from 5 to 5000 in steps of 5.
-
Use a range to print out the numbers from -500 to 0.
-
Using a range, print the first 15 numbers in the Fibonacci sequence.
-
Without overwriting the starting code, add changes to it which will make it print the following:
1 11 100 99 98 2
Starting code:
for (i in 1..5) { println(i) for (j in 11..20) { println(j) for (k in 100 downTo 90) { println(k) } } }
-
Declare a variable called
num
(Int
) and assign it any value you choose. Also declare a variable calleddnum
(Double
) and do the following:- in one expression:
- if
num
> 100, assigndnum
-234.567 - if
num
< 100, assigndnum
4444.555 - if
num
== 100, assigndnum
0.0
- if
- print the value of
dnum
.
- in one expression: