This book is now obsolete Please use CSAwesome instead.
3.9. Common Mistakes¶
forgetting that Java is case sensitive -
myScoreis not the same as
forgetting to specify the type when declaring a variable (using
name = value;instead of
type name = value;)
using a variable name, but never declaring the variable.
using the wrong name for the variable. For example calling it
studentTotalwhen you declare it, but later calling it
using the wrong type for a variable. Don’t forget that using integer types in calculations will give an integer result. So either cast one integer value to double or use a double variable if you want the fractional part (the part after the decimal point).
==to compare double values. Remember that double values are often an approximation. You might want to test if the absolute value of the difference between the two values is less than some amount instead.
assuming that some value like 0 will be smaller than other
intvalues. Remember that
intvalues can be negative as well. If you want to set a value to the smallest possible