President Reagan promised today to maintain the military buildup he launched four years ago, telling the graduating class of the U.S. Naval Academy that it is "too costly for America not to be prepared."

Ignoring the series of setbacks his administration has suffered recently on defense issues, Reagan shook hands with all 1,032 graduates and vowed that "I will do everything in my power to make certain the country gives you the tools and equipment you need to do your job."

During the graduating midshipmen's four years at the academy, Reagan said, "much progress had been made" toward his goal of rebuilding "America's weakened defenses." He did not mention the pending House version of the budget, which would freeze defense spending without allowing for inflation, nor his embattled proposal to deploy at least 100 MX missiles.

The president made an oblique reference to scandals in defense procurement, which led Navy Secretary John F. Lehman Jr. -- who introduced Reagan today -- to penalize General Dynamics Corp. on Tuesday for "pervasive" business misconduct.

"We've moved forward to ferret out waste and inefficiency," Reagan said.

He said, as he has in the past, that "those stories about outrageously expensive hammers and bolts" are actually "success stories" because they showed that his administration was "finding the waste and cutting it out."

The president was warmly received by an audience of 15,000, many of them relatives and friends of the graduating midshipmen, and he joined in the festive mood of the crowd at Navy-Marine Corps Memorial Stadium. Many of the midshipmen shouted and waved after receiving their graduation certificates and one gave the president an enthusiastic "high five" instead of the traditional handshake. Reagan returned it, smiling broadly.

Reagan's speech today restated his familiar theme that military unpreparedness is an invitation to aggression and war. But he avoided an emotional tone in his discussion of Soviet military prowess, making what an aide termed "a deliberate attempt to hold his ground without being provocative."

"Today, as throughout our history, it is strength, not weakness, that will keep the peace," Reagan said. "It is about time that those who place their faith in wishful thinking and good intentions get the word."

Reagan contended that the Navy's role in deterrence went far beyond preventing nuclear war.

"The spectrum of conflict ranges from terrorism and guerrilla warfare through conventional and nuclear confrontation," he said. " . . . . We hope to dissuade hostile action at any level by persuading potential aggressors that, whatever their target, they will lose more than they will gain."

The president said a continued naval buildup is necessary because the Soviet Union had converted a navy once preoccupied with coastal defense "into an offensively designed, blue-water navy, a formidable threat to peace and stability throughout the world."

Reagan said the United States had allowed its military strength to decline in the decade before he took office, "perhaps as a result of confusion stemming from the Vietnam war." Citing the Soviet invasion of Afghanistan, Reagan said: "A weaker America did not mean a more peaceful world."

Reagan was presented with a navy-blue bathrobe decorated with the stripes of a five-star admiral and emblazoned in gold with the words "Commander in Chief." The president turned the bathrobe inside out to reveal a football slogan -- "Beat Army" -- that evoked a cheer from the crowd.