Derivation of "Ask not what your country can do for you--ask what you can do for your country."
In A Thousand Days (Houghton Mifflin, 1965) Arthur Schlesinger, Jr. relates in a footnote on page 4, that John Kennedy kept a looseleaf notebook of quotations, and that as early as 1945 he had entered a quotation ascribed to the 18th century French philosopher Jean Jacques Rousseau: "As soon as any man says of the affairs of state, What does it matter to me?, the state may be given up as lost." (No source cited.)
Van Wyck Brooks's New England: Indian Summer (1940) contains remarks made by the Mayor of Haverhill, Massachusetts at the funeral of John Greenleaf Whittier in which is the following: "Here may we be reminded that man is most honored, not by that which a city may do for him, but by that which he has done for the city." And, Supreme Court Justice Oliver Wendell Holmes, in a Memorial Day address is 1884 stated: "It is now the moment when by common consent we pause to become conscious of our national life and to rejoice in it, to recall what our country has done for each of us, and to ask ourselves what we can do for our country in return."
Guy Emerson in The New Frontier: A Study of the American Liberal Spirit... (Henry Holt and Co., 1920) placed special emphasis on this thought on the last page of the text, in italics: "...men and women are born to put more into their country than they take out of it." (The copy of the book in the Kennedy Library was a gift to the President received at the White House in April, 1961.)
President Kennedy may have encountered all these sources in his education. He expressed similar ideas on at least two occasions prior to the inauguration. On July 15, 1960 in his address to the Democratic National Convention accepting the Party's nomination for President he defined his "New Frontier" saying: "It sums up not what I intend to offer the American People, but what I intend to ask of them." On September 5, 1960, in Detroit, he said: "The new frontier is not what I promise I am going to do for you. The new frontier is what I ask you to do for your country." Incidentally, in a earlier draft of the Inaugural Address the line had been: "Ask not what your country is going to do for you... (etc.)"