Brandon Minoff, a student at Stoneman Douglas High School, said in an interview with CNN that a teacher assigned him to work with Mr. Cruz on a group project two years ago. Mr. Cruz was quiet in class but opened up during their project, Mr. Minoff said, telling him that he had been kicked out of two private schools, had been held back twice and aspired to join the military.

“He was always to himself and never tried to associate himself with anyone,” Mr. Minoff said. “As far as I know, he didn’t have any friends.”

School officials declined to say why Mr. Cruz no longer attended Douglas High School. But Amanda Samaroo, whose daughter, Elizabeth, attended the school while he was a student there, said he had been expelled for bringing knives on campus. “Her friends have said he was known to always be mentally ill and would kill animals,” Ms. Samaroo said.

Helen Pasciolla, who is retired, lives on an elegant street in the Pine Tree Estates development in Parkland, three houses down and across from where the Cruz family resided until about a year ago. Ms. Pasciolla said that Mr. Cruz told her that the family had to move out of their one-story beige house and sell it because they could no longer afford it.

She said that Mr. Cruz has a brother, Zachary, and that both boys were adopted. Their adoptive father died some years ago, she added.

Ms. Pasciolla said that the boys’ mother, Lynda Cruz, had regular problems with their behavior. On occasion, she said, the mother would resort to calling the police to have them come over to try to talk some sense into her sons.

Image The suspect arrested in connection with Wednesday’s shooting at a Florida high school, which left at least 17 people dead, was identified by the sheriff as 19-year-old Nikolas Cruz. Credit... via Social Media

“I think she wanted to scare them a little bit,” Ms. Pasciolla said. “Nikolas has behavioral problems, I think, but I never thought he would be violent.”

When she saw his picture on TV on Wednesday after the shooting, Ms. Pasciolla said that she thought to herself, “Oh, my God, that’s the kid who lived down the street.”

Sheriff Israel said that the authorities did not yet know the motive for the killing, but were learning more about Mr. Cruz through his social media pages, which he described as “very, very concerning.”

Screen shots of an Instagram page said to belong to Mr. Cruz show many photos of a man holding firearms and ammunition used in a semiautomatic AR-15 rifle. One photo shows several guns, including rifles with scopes, lying on a bed. Another appears to show a frog that had been killed.

After Mr. Cruz left Douglas High School, he took a job at a Dollar Tree store about a mile and a half from the school. A person who answered the phone at the store on Wednesday evening said that Mr. Cruz worked as a cashier and was well liked by his colleagues.

“He was a great guy,” the person said.

He added that he last saw Mr. Cruz about a year ago before he transferred to another Dollar Tree store closer to his home.

Another student at Douglas High School, Ocean Parodie, told The Daily Beast that he visited the store after Mr. Cruz was expelled to check on him. “He said he was expelled and was happy that he was thrown out,” Mr. Parodie said. “I felt bad for him.”