0

How do I add two numbers with a string and get an output

int x = Integer.parseInt("2"); int y = Integer.parseInt("3"); int z = x + y; //5 I tried this... but nothing shows up.

15th Mar 2017, 7:20 PM
Mason S
Mason S - avatar
7 Answers
+ 2
Try this: var x = parseInt("2" ); var y = parseInt("3"); var z = x+y; console.log(z);
15th Mar 2017, 7:42 PM
FMC Drummer
FMC Drummer - avatar
+ 1
You want to print that number in console or where? In a html file?
15th Mar 2017, 10:54 PM
FMC Drummer
FMC Drummer - avatar
0
try this var x= "3"; var y= "2"; x *= 1; y *=1; var z=x+y; console.log(z);
18th Mar 2017, 6:47 PM
Leo Flame
Leo Flame - avatar
0
Just trying to get an output. Haven't done anything with HTML file. I've done all of this with the code playground in app, and nothing is showing up. The page is just blank. var x= ("3"); var y= ("2"); x *=1 y *=1 var z=x+y; Console.log(z); Is there any way to see error messages, etc here?
18th Mar 2017, 7:16 PM
Mason S
Mason S - avatar
0
add document.write(z);// after console.log
18th Mar 2017, 7:21 PM
Leo Flame
Leo Flame - avatar
0
Mason S, please go check my profile, i did an example for you so you can better understand :D
19th Mar 2017, 2:52 PM
FMC Drummer
FMC Drummer - avatar
- 1
Still didn't work...:/ var x= parseint("3"); var y= parseint("2"); var z=x+y; console.log("z");
15th Mar 2017, 9:05 PM
Mason S
Mason S - avatar