From 4bbf187cd28f860917ab1c6227b32fdebec37d3d Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Wed, 6 May 2020 06:33:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=A6=E4=BD=9C=E6=8C=89=E4=B8=8B=200=20?= =?UTF-8?q?=E4=BB=A5=E5=A4=96=E7=9A=84=E6=95=B8=E5=AD=97=E8=A6=81=E6=80=8E?= =?UTF-8?q?=E9=BA=BC=E8=99=95=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidCalculator/Calculator.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AndroidCalculator/Calculator.swift b/AndroidCalculator/Calculator.swift index a9c6f6b..8fa20b4 100644 --- a/AndroidCalculator/Calculator.swift +++ b/AndroidCalculator/Calculator.swift @@ -37,8 +37,18 @@ class Calculator { formula.append(formula.popLast()! + text) } + case "1", "2", "3", "4", "5", "6", "7", "8", "9": + if formula.last == "0" { + formula.removeLast() + formula.append(text) + } else if ["+", "-", "×", "÷"].firstIndex(of: formula.last!) != nil { + formula.append(text) + } else { + formula.append(formula.popLast()! + text) + } + default: - formula.append(text) + print(formula) } } }