Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,26 @@
|
|||
object TPKa extends App {
|
||||
final val numbers = scala.collection.mutable.MutableList[Double]()
|
||||
final val in = new java.util.Scanner(System.in)
|
||||
while (numbers.length < CAPACITY) {
|
||||
print("enter a number: ")
|
||||
try {
|
||||
numbers += in.nextDouble()
|
||||
}
|
||||
catch {
|
||||
case _: Exception =>
|
||||
in.next()
|
||||
println("invalid input, try again")
|
||||
}
|
||||
}
|
||||
|
||||
numbers reverseMap { x =>
|
||||
val fx = Math.pow(Math.abs(x), .5D) + 5D * (Math.pow(x, 3))
|
||||
if (fx < THRESHOLD)
|
||||
print("%8.3f -> %8.3f\n".format(x, fx))
|
||||
else
|
||||
print("%8.3f -> %s\n".format(x, Double.PositiveInfinity.toString))
|
||||
}
|
||||
|
||||
private final val THRESHOLD = 400D
|
||||
private final val CAPACITY = 11
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue