From d15ca0a6de856a1b4996f49c838269333895ea01 Mon Sep 17 00:00:00 2001 From: Satwato Dey <40371227+Satwato@users.noreply.github.com> Date: Thu, 16 May 2019 22:04:36 +0530 Subject: [PATCH] Lambda calc --- trial.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/trial.kt b/trial.kt index 633e6c8..0b3dc6d 100644 --- a/trial.kt +++ b/trial.kt @@ -8,20 +8,21 @@ fun main(){ print("Enter an operator (+, -, *, /): ") val operator = reader.next()[0] - val result: Float - when (operator) { - '+' -> result = first + second - '-' -> result = first - second - '*' -> result = first * second - '/' -> result = first / second + val total={first:Float,second:Float, operator:Char-> + + when (operator) { + '+' -> first + second + '-' -> first - second + '*' -> first * second + '/' -> first / second else ->{ println("Error! operator is not correct") - return } } + } - System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, result) + System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, total(first,second,operator)) } \ No newline at end of file