
Armed police were called to a university library in Swansea because a student was carrying an imitation gun in his bag, a court heard.
Edward Thomas, 21, of Crewe, had the fake Glock pistol at the Trinity St David's business school in November.
He pleaded guilty to possessing an imitation firearm in a public place at the city's magistrates' court on Wednesday.
Thomas had a 16-week prison sentenced suspended for two years.
The court heard that while the gun could only fire blanks, it was indistinguishable from a real one.
After the weapon was spotted in his bag and the police were called, armed officers approached Thomas in the library and arrested him.
District Judge Neil Thomas said he must have realised his actions "would cause alarm and distress."
He was also subjected to an overnight curfew for the next 12 weeks.
A university spokeswoman said she believed Thomas intended to withdraw from his course.
She added that since the incident, new security measures had been implemented on campus.
