+ 6
I need a little help with a calculator program
I tried to do a calculator program. I added the buttons and a textfield to show the user's income and output as well. My problem starts when somebody write for example "5+2". It is a String value what a tried to transform to int value to calculate the sum (Integer.parseInt(textfield.getText()). After that I would like to transform the result back String value to add this value to the textfield (String.instanceof(Integer.parseInt(textfield.getText().But I always get a NumberformatException. Anybody can help?
4 ответов
+ 9
try this ,
String numberone = edittext.getText().toString();
String numbertwo = edittext1.getText().toString();
int addition = Integer.parseInt(numberone) + Integer.parseint(numbertwo);
TextView.setText(String.valueof(addition));
+ 6
because you can't parse 5+2 as one int because 5 is one integer, + is operator and 2 is another integer. You could try to threat that string as array of characters and parse his first and second character.
+ 6
you're welcome 😁
+ 3
Thank you to all the help. I will try your suggestions.