1. Exercise 1: Triple
-
Declare a constant Triple that contains three Int values. Use this to store your birthdate (month, day, year).
-
Extract the values in the triple into three constants named month, day and year.
-
In one line, read the month and year values into two constants. You’ll need to employ the underscore to ignore the day.
// TODO
fun main() {
// 1.
println("1.")
val dob = // TODO
println(dob)
// 2.
println("\n2.")
// TODO
println("day = $day, month = $month, year = $year")
// 3.
println("\n3.")
// TODO
println("day = $dd, year = $yyyy")
}
2. Exercise 2: Boolean, if, when, loop
-
Create a constant called
shipmentWeight
and set it to a number between 1 and 100.Create a constant called
isPackage
that uses Boolean logic to determine if the shipment weighs between 2 and 32 kg. (shipments ⇐ 2Kg are letters, > 32 kg is not allowed) -
Write an
if
statement to print outletter
if the shipment weighs under or equals 2,package
when the shipment weighs over 2 kg and maximum 32 kg, andtoo heavy - not allowed
when the shipment weighs over 32 kg.. -
Write an
if
expression to print outletter
if the shipment weighs under or equals 2,package
when the shipment weighs over 2 kg and maximum 32 kg, andtoo heavy - not allowed
when the shipment weighs over 32 kg.. -
Write an
when
expression to print outletter
if the shipment weighs under or equals 2,package
when the shipment weighs over 2 kg and maximum 32 kg, andtoo heavy - not allowed
when the shipment weighs over 32 kg.. -
Create a multiplication table ("das kleine Einmaleins"). Use loops.
2.1. Output:
1 x 1 - Tabelle 1 2 3 4 5 6 7 8 9 10 ----------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 9 10 2 | 2 4 6 8 10 12 14 16 18 20 3 | 3 6 9 12 15 18 21 24 27 30 4 | 4 8 12 16 20 24 28 32 36 40 5 | 5 10 15 20 25 30 35 40 45 50 6 | 6 12 18 24 30 36 42 48 54 60 7 | 7 14 21 28 35 42 49 56 63 70 8 | 8 16 24 32 40 48 56 64 72 80 9 | 9 18 27 36 45 54 63 72 81 90 10 | 10 20 30 40 50 60 70 80 90 100
For formatting the output, search the internet |
-
Suppose the squares on a chessboard are numbered left to right, top to bottom, with 0 being the top-left square and 63 being the bottom-right square. Rows are numbered top to bottom, 0 to 7. Columns are numbered left to right, 0 to 7. Given a current position on the chessboard, expressed as a row and column number, calculate the next position on the chessboard, again expressed as a row and column number. The ordering is determined by the numbering from 0 to 63. The position after 63 is again 0.