It uses a type of data that is not primitive, called String
.
Note that to compare two strings do not use the ==
and yes the equals()
. Example:
if (stringDigitada.equals("São Paulo")) {
...
}
You should look up a tutorial on Java. Or on second thought, I don’t know why you’re learning basic programming with Java, whether it’s college stuff or something. I think it would be better to start with a structured language and not an object-oriented language. Java is object-oriented, which makes things more complicated, for example a String
is an object, which is a type of data that has functions attached to it (note in the above example that the object stringDigitada
has a function equals()
added to it, which is being called so: stringDigitada.equals(...)
). These functions are called "methods".
If you want to learn programming and don’t have a special reason to use Java, I suggest that you first choose a language that supports structured programming such as Python or C and then look for a suitable learning material to guide you along this path, that can be a tutorial, book or video lessons. Maybe even before doing so you will look for material to learn about something called "programming logic", which will probably be taught in some pseudo language like Portugol (although it is possible to find material on programming logic already in the desired programming language).
I hope that these guidelines can be useful.
Why not string? If you use numbers, you will need to map cities in order to be able to relate them. Better to do it directly with strings.
– user28595