First, it's important to know that the chemical formula for water is #H_2O#. This means that one molecule of water is made of two hydrogen atoms and one oxygen atom.
Then, we need to find how many moles of water there are in #"18 g"#. (We need to do this, because knowing the number of moles of water will help us convert from grams to number of atoms!)
To find how many moles of water there are in #"18 g"#, we have to divide #"18 g"# by the number of grams in one mole of water, also known as the molar mass of water:
#"number of moles" = "mass of sample"/"molar mass"#
#"number of moles" = "18 g"/("molar mass of H"xx2 + "molar mass of O")#
#"number of moles" = "18 g"/("1.008 g/mol"xx2 + "16.00 g/mol") = "18 g"/("18.02 g/mol") ≈ "1 mole"#
In #1# mole of water, there are #6.022 xx 10^(23)# molecules—that's how the mole was defined!
And, since the chemical formula for water is #H_2O#, #1# mole of water corresponds to #1# mole of oxygen atoms.
Therefore, there will be #6.022 xx 10^(23)# oxygen atoms in #1# mole, or #"18 g"# of water.