John B. Anderson yesterday strongly hinted he would drop his three-month-old independent presidential candicacy if Sen. Edward Kennedy wins the Democratic nomination.

After an extraordinary 45-minute meeting in Kennedy's office, Anderson told a joint news conference he had made no promise to withdraw from the race if Kennedy is the Democratic nominee.

But the thrust of his remarks indicated he would likely quit the race if someone other than President Carter is the nominee.

"Obviously, should there be a different decision from the one that has been so widely predicted -- should a different decision emerge from the Democratic convention -- it would only be prudent for one like myself who believes very much in the two-party system to perhaps reconsider what my position would be," he said.

Moments later, reminded that this represented a major change from a position he advocated earlier this week. Anderson added: "I'm running not because I'm attacking the two-party system, but because I'm attacking the nominating process that apparently is destined to give us nominees like President Carter and Ronald Reagan."

The surprise meeting between the two presidential contenders was held at Kennedy's invitation. A throng of more than 200 reporters and spectators packed the narrow corridor outside the senator's suite in the Dirksen Office-Building amid rumors of a Kennedy-Anderson alliance.

"It was hoped both sides would get something out of this," Anderson press secretary Michael Rosenbaum said later.

Kennedy hoped Anderson's remarks would give him leverage at the Democratic National Convention, where he is lobbying for a rule that would allow Carter delegates to abandon the president if they wished.

Carter is going into the Aug. 11-14 convention in New York City with at least 300 more delegate votes than needed to win nomination. But a Louis Harris poll released earlier this week showed his national approval rating at only 22 percent, an all-time low for a president in modern times. And a California poll by the Mervin D. Field organization shows the president running third in that state behind Republican nominee Reagan, in first place, and Anderson, in second.

Anderson's statements allow Kennedy to claim that he would be a much stronger candidate in the fall than Carter because he wouldn't have to contend with an independent candidacy that is seen as hurting Carter more than Reagan.

What Anderson stands to gain by yesterday's remarks was far less clear. Since he announced his independent candidacy April 24, he has run as a "different" kind of politician. The alliance with Kennedy appeared to cast him in the role of a political deal-maker and raised questions about the seriousness of his candidacy.

Kennedy offered only two things to Anderson in the meeting. Kennedy said that should he win the nomination, he would agree to a three-way debate with Anderson and Reagan, and would direct the Democratic National Committee to "halt using its limited resources to block his [Anderson's] candidacy."

Carter, after initially refusing to debate Anderson, has said he would debate any candidate with a theoretical chance of winning, but only after a one-on-one face-off with Reagan. Reagan has agreed to a three-way debate, and Kennedy telephoned him yesterday to have him reiterate that.

But Reagan's staff initially didn't believe the call was a real one. And it took three calls from Kennedy before Reagan's staff was convinced the call was not a prank.

David Garth, Anderson's media adviser and chief strategist, said he hoped the meeting would help lure liberal Democrats to the Anderson campaign.

"If Anderson is going to win this election, he's going to need the support of a lot of Democrats," he said. "Believe me, between now and Labor Day we're going to be meeting with a lot of Democrats -- Kennedy supporters included -- publicly and privately."

At their joint press conference, Kennedy and Anderson portrayed themselves as almost blood brothers on a host of issues.

Kennedy said he has a "very high regard" for Anderson's efforts "to help the American people reach solutions to their central problems." Anderson said he has long admired Kennedy's "willingness to debate opponents" and "stake out courageous positions."

"We are in wide agreement on a wide range of issues," the Illinois congressman added.

This was a half truth at best. The two men agree on a handful of litmus issues important to liberal voters -- gun control, the Equal Rights Amendment and abortion. But their voting records in Congress are vastly different and they have staked out campaign positions that often are diametrically opposed.

Kennedy, for example, favors wage and price controls, Anderson opposes them. Anderson favors a 50-cent gasoline tax to encourage fuel conservation, Kennedy opposes the tax.

In a related matter, Anderson's attorneys yesterday filed suit in U.S. District Court in Washington charging that the Federal Election Commission's interpretation of the law on providing public financing for presidential campaigns discriminates against independents.