Advertisement
Muhammad_Farroos

calculator sederhana

Jun 15th, 2021 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. fun main(){
  2. calculate('%', 11.0, 5.0)
  3. }
  4.  
  5. fun calculate(simbol: Char, a: Double, b: Double){
  6. var result: Double? = null
  7. if(simbol == '+'){
  8. result = a + b
  9. } else if (simbol == '-'){
  10. result = a - b
  11. } else if (simbol == '/'){
  12. result = a / b
  13. }else if (simbol == '*'){
  14. result = a * b
  15. } else if (simbol == '%'){
  16. result = a % b
  17. } else {
  18. println("Operator tidak dikenali oleh program")
  19. }
  20. if (result != null){
  21. print("hasil dari \n$a $simbol $b =" + result)
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement