Sex offender avoids prison term in court