There are a few reasons to use setters and accessors as opposed to simply making variables public.
1. Separation of concerns - The consumers of a class shouldn't know, or even care, whether what they're accessing is a primitive variable, or something more complex. For example, let's say I had a Car class, and that car has a horsepower. You can get the horsepower by calling the getHorsepower() method, and you can set it with setHorsepower(int power).
Now, a consumer of this class really doesn't care what goes on under the hood, just that there is a horsepower method. But what if, on the backend, setting the horsepower meant changing the engine? When you call setHorsepower, it will find an engine that can provide that, and call the private method setEngine(Engine newEngine) to make sure that the car's behavior is consistent!
2. Code maintainability - When you set up the class, it may make sense to only have a public variable, but you quickly find that you need to do error checking on the variable, or you need to have a change in that variable update another object. If you provided the public variable, you would need to change all the classes that use that and then have them either A) Implement all the functionality you need them to like error checking, or B) Change them to use an accessor. By having them use the accessor, you can modify all of that in one place instead of having to keep track of all the places that use that variable.