Import android os. Bundle


Download 141 Kb.
Pdf ko'rish
bet10/15
Sana20.11.2023
Hajmi141 Kb.
#1789524
1   ...   7   8   9   10   11   12   13   14   15
Bog'liq
Qodirov mobil ilovakar 2 dedline





}); 

 
private String evaluateExpression() { 
String expression = inputStringBuilder.toString(); 
String[] tokens = expression.split(" "); 
double operand1 = Double.parseDouble(tokens[0]); 
String operator = tokens[1]; 
double operand2 = Double.parseDouble(tokens[2]); 
 
double result = 0; 
switch (operator) { 
case "+": 
result = operand1 + operand2; 
break; 
case "-": 
result = operand1 - operand2; 
break; 
case "*": 
result = operand1 * operand2; 
break; 
case "/": 
if (operand2 != 0) { 
result = operand1 / operand2; 
} else { 
throw new ArithmeticException("Division by zero"); 

break; 



 
return String.valueOf(result); 

 
private void updateResultText() { 
resultTextView.setText(inputStringBuilder.toString()); 


 
activity_main.xml: 
 

xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity"> 
 

android:id="@+id/resultTextView" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 

Download 141 Kb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   15




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling