Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I multiply two String variables?

Tags:

java

I want to multiply two String variables and want to store the answer in a new variable. How can I do this?

I have already tried to do the simple:

String t2 = t1 * m1;

The error was that * was undefined. So, I tried adding:

import java.math.'whatever';

That didn't fix the error.

like image 212
Ryan Avatar asked Dec 27 '22 01:12

Ryan


1 Answers

use

String t2 = String.valueOf(Integer.parseInt(t1) * Integer.parseInt(m1)) 
like image 79
Cris Avatar answered Jan 09 '23 03:01

Cris