5g is the cube's mass, not its weight.
The volume of the cube = (2cm x 2cm x 2cm) = 8 cm³ .
Density = (mass) / (volume) = (5g / 8cm³) = 0.625 gm/cm³ .
The cube will sink in any liquid whose density is less than 0.625 gm/cm³.
It will float in water, whose density is 1 gm/cm³.