+ 1

if statement only use with variables i.e int. OR it can use with String.

when i write String money = "10000"; and then apple if statement if(money>5000){ I need to know this is write or wrong.

20th Jun 2017, 6:50 AM
Umair Rasool
Umair Rasool - avatar
4 Réponses
+ 1
as u declared "money" as String this should present an error, so it is wrong, but in some languages, like pyhton, u can define x = 5000 and use the same "x" as String and Integer, the program change the type when u change the usage
20th Jun 2017, 7:01 AM
Juliano Ventola
Juliano Ventola - avatar
+ 1
right*
20th Jun 2017, 8:49 AM
Limitless
Limitless - avatar
0
This won't work because Java is quite strict about types. You will have to use Integer.parseInt(money)
20th Jun 2017, 7:03 AM
Kürti Szabolcs
Kürti Szabolcs - avatar
0
The "if" statement actually only works with boolean values (true or false) :) It is the operators ( > , < , ==, etc) that require certain types in order to work. In this case, you cannot compare with the '>' operator a String and a number.
20th Jun 2017, 7:59 AM
Bogdan Sass
Bogdan Sass - avatar