Get the length of the data structure where you have store the values. When you are one less than the total length, print a comma and "and" and then print the value.