This is not a simple, here it is kind of thing. It just reuires some code writing.
I would suggest you break it down into smaller tasks.
A check for uniqueness means go compare to all others. It is your choice if you involve sql commands or get them all into code and check.
After you add a 1 then any next match needs to go to index of 2 and so on. You just got to write the code. Try it in smaller logic steps.
Also why does the unique id need to be made from their last name and first initial in the first place?
This problem can be solved by creating a HashMap and loading all the users from the database into that map. Now you can check if there is one that already exists by hash.keyset.containskey(). The key would be the user id and if one exists add 1 to it like hash.put(userid, new Integer(number)); Keep adding a 1 to this number for more similarities in the map.