+ 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.
4 Antworten
+ 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
+ 1
right*
0
This won't work because Java is quite strict about types. You will have to use Integer.parseInt(money)
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.