Navy Secretary John F. Lehman Jr., declaring both the Navy and Marine Corps to be in "very good shape," made formal his resignation as Pentagon sources disclosed that best-selling author James H. Webb had been selected as his replacement. Webb, currently the assistant defense secretary for reserve affairs, declined to discuss his plans. But officials, speaking only on condition they not be named, said Defense Secretary Caspar W. Weinberger had prevailed upon him to scuttle his own retirement plans and replace Lehman. The 40-year-old Webb is a highly decorated Vietnam veteran who announced on Feb. 2 he was resigning to return to private life as a novelist. One of Webb's books, "Fields of Fire," about the Vietnam War, was published in 1977, and another book, "A Country Such as This," appeared in 1981. Both were nominated for a Pulitzer Prize.