Why does my Code not work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
27th Aug 2023, 3:45 PM
Antony
Antony - avatar
3 Answers
+ 3
Hellu, for the first you created the variable inside of the if statements, you will not be able to use the variable outside of the if statements so add this line above the if statements somewhere int result = 0; then remove the int and replace with result = num1 + num2; And i would use char instead of String for the oparator char operator = sc.next().charAt(0); Also make sure to change "+" to '+' Should work
27th Aug 2023, 5:08 PM
JavaBobbo
JavaBobbo - avatar
+ 3
Good good👍
27th Aug 2023, 5:41 PM
JavaBobbo
JavaBobbo - avatar
+ 1
Thanks, it works now JavaBobbo
27th Aug 2023, 5:24 PM
Antony
Antony - avatar