An object will be floating in water if the density is lower and will be sink if the density is higher. Water density would be 1000g/liter or 1g/ml. To determine whether the object float or sink you need to calculate both object density.
The density of object A would be: 2g/ 0.5liter= 4g/liter The density of object B would be: 3g/ 5liter= 0.6g/liter
It is clear that the object is much lighter than water so both objects would float.