How Do You Assign a Variable in Groovy to Be an Integer Value?

Problem scenario
A Groovy program is returning an incorrect value for an integer variable. What is wrong?

Possible solution #1
Check the logic of your program. Use the println command to see the earliest point when this variable is assigned an incorrect value. This helps you pinpoint the problem.

Possible solution #2
Is the variable being assigned a number in quotes like this?

int i = "0"

You should remove the quotes from the numeral zero.

Leave a comment

Your email address will not be published. Required fields are marked *