1
1
Fork 0

Sync with the book text: incorporated the latest changes to the examples

This commit is contained in:
Svetlana Isakova 2021-09-01 12:54:08 +02:00
parent c18ef412b3
commit da750a2973
3 changed files with 18 additions and 11 deletions

View File

@ -19,8 +19,8 @@ fun quadraticZeroes(
"Negative underRadical: $underRadical"
}
val squareRoot = sqrt(underRadical)
val root1 = (-b - squareRoot) / 2 * a
val root2 = (-b + squareRoot) / 2 * a
val root1 = (-b - squareRoot) / (2 * a)
val root2 = (-b + squareRoot) / (2 * a)
return Roots(root1, root2)
}
@ -33,7 +33,7 @@ fun main() {
quadraticZeroes(3.0, 4.0, 5.0)
} eq "IllegalArgumentException: " +
"Negative underRadical: -44.0"
val roots = quadraticZeroes(3.0, 8.0, 5.0)
roots.root1 eq -15.0
roots.root2 eq -9.0
val roots = quadraticZeroes(1.0, 2.0, -8.0)
roots.root1 eq -4.0
roots.root2 eq 2.0
}

View File

@ -2,15 +2,22 @@
package namedanddefault
class DefaultArg
val da = DefaultArg()
fun g(d: DefaultArg = da) = println(d)
fun h(d: DefaultArg = DefaultArg()) =
println(d)
fun main() {
g()
g()
h()
h()
}
/* Sample output:
DefaultArg@28d93b30
DefaultArg@1b6d3586
namedanddefault.DefaultArg@7440e464
namedanddefault.DefaultArg@7440e464
namedanddefault.DefaultArg@49476842
namedanddefault.DefaultArg@78308db1
*/

View File

@ -3,10 +3,10 @@ import atomictest.eq
fun main() {
val nums = mutableListOf(0)
for (i in 4 until 100 step 4) { // [1]
if (i == 8) continue // [2]
if (i == 40) break // [3]
for (i in 4 until 100 step 4) { // [1]
if (i == 8) continue // [2]
if (i == 40) break // [3]
nums.add(i)
} // [4]
} // [4]
nums eq "[0, 4, 12, 16, 20, 24, 28, 32, 36]"
}