Display user role on profile page

I would like to display what role a user belongs to on their profile page, e.g.: “Bob (Administrator)”, “Jane (Subscriber)”.

I had a look on the WordPress forums and found some suggestions on how to do this but couldn’t get them to work, and wondered if it might be to do with having Buddypress installed. For example I found this:

if displaying on their profile page then I don’t think you really need to loop over an array of user_id’s/roles, if you indeed do need to instantiate a new user then you probably need to pass to it bp_displayed_user_id()

You should be able to see what you have in the $user by var_dump – ing it out to see what it has