Using 当然 as an exclamation? I'm wondering...

To answer someone's question as to whether something is so or not, can you simply reply, "of course it is!" just as we do in English?

Example: 
Can you swim？ (你会游泳吗？）
Of course I can swim! (As in, that's a ridiculous question). (当然啊！）

Thanks in advance!
Yes.
In fact, you can use any word as an exclamation, especially in speech. I'm not aware of any language where this is ungrammatical. Example:

Q: What's your favourite Chinese word?
A: 当然！