Advertisement
Guest User

Calculator

a guest
Nov 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1.  
  2. import java.util.*
  3. fun main(args: Array<String>) {
  4. val reader = Scanner(System.`in`)
  5. print("Zadaj prvé čslo: ")
  6. val first = reader.nextDouble()
  7. println("Zadaj druhé číslo:")
  8. var second = reader.nextDouble()
  9. println("Zadaj tretie číslo:")
  10. var third = reader.nextDouble()
  11. println("Zadaj štvrté číslo:")
  12. var fourth = reader.nextDouble()
  13. println("Zadaj piate číslo:")
  14. var fifth = reader.nextDouble()
  15. println("Zadaj šieste číslo:")
  16. var sixth = reader.nextDouble()
  17. println("Zadaj siedme číslo:")
  18. var seventh = reader.nextDouble()
  19. println("Zadaj ôsme číslo:")
  20. var eight = reader.nextDouble()
  21. println("Zadaj deviate číslo:")
  22. var ninth = reader.nextDouble()
  23. print("vyber si operáciu (+, -, *, /): ")
  24. val operator = reader.next()[0]
  25. val result: Double
  26. when (operator) {
  27. '+' -> result = first + second + third + fourth + fifth + sixth + seventh + eight + ninth
  28. '-' -> result = first - second - third - fourth - fifth - sixth - seventh - eight - ninth
  29. '*' -> result = first * second * third * fourth * fifth * sixth * seventh * eight * ninth
  30. '/' -> result = first / second / third / fourth / fifth / sixth / seventh / eight / ninth
  31. // operator doesn't match any case constant (+, -, *, /)
  32. else -> {
  33. System.out.printf("Error! operator is not correct")
  34. return
  35. }
  36. }
  37. System.out.printf("%.1f %c %.1f %c %.1f %c %.1f %c %.1f %c %.1f %c %.1f %c %.1f %c %.1f = %.1f", first, operator, second, operator, third, operator, fourth, operator, fifth, operator, sixth, operator, seventh, operator, eight, operator, ninth, result)
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement