Image copyright Reuters Image caption Mr Obama accused Mr Trump of mostly being interested in getting retweets and headlines instead of thinking about what is required to keep America safe

US President Barack Obama has said that international leaders "have good reason to be rattled" by pronouncements made by the Republican White House contender, Donald Trump.

Speaking on the sidelines of the G7 summit in Japan, Mr Obama said Mr Trump had shown a cavalier and ignorant attitude towards world affairs.

Mr Obama said foreign leaders were surprised by his nomination.

Mr Trump said it was a "good thing" foreign leaders were rattled.

Protests turn violent at Trump rally

Illegal immigration raises heat in US election

Could Trump deport every single illegal immigrant?

Why Mexicans are troubled by Trump

Trump's migrant plan attacked by rivals

"They are not sure how seriously to take some of his pronouncements, but they're rattled by him - and for good reason, because a lot of the proposals that he's made display either ignorance of world affairs or a cavalier attitude," the president said.

Donald Trump's foreign policy pronouncements

Donald Trump's foreign policy assessed

Trump's foreign policy: Brilliant or bluster?

"[He only has] an interest in getting tweets and headlines instead of actually thinking through what it is that is required to keep America safe and secure and prosperous, and what's required to keep the world on an even keel."

Image copyright AP Image caption Mr Trump is now just a few votes short of becoming the Republican candidate

The president also downplayed Democratic party concerns about the long-running primary fight between Hillary Clinton and Bernie Sanders.

He pointed out that occasionally in a primary "people get grumpy".

But he insisted that one of the main differences between Democrats and Republicans this year was the fact that Democratic candidates were not so far apart ideologically.

With Mr Trump's opponents for the Republican nomination dropping out of the race, he is now just a few votes short of securing the 1,237 delegates needed to officially become the Republican candidate for November's presidential election.