JAVA prepared on the basis of common errors

A common error: undeclared variables, uninitialized, unused

Here Insert Picture Description
Variables must be declared prior to use and a type of assignment (initialization). life appearing in the above code has not been declared and assigned, so I can not run properly. At the same time the strict Java case-sensitive, so the above code Life and life are considered two different variables. And if you declare a variable in the program but has not been used, which will also be a potential error and should be deleted. At the same time if you use Eclipse, NetBeans, you will receive a warning message about unused variables.

Common Mistakes two: integer overflow

Here Insert Picture Description
As described above, if a variable is assigned a too large (in terms of memory size) values, that they can not store the value, which is called overflow. Java does not give a warning or error message on overrun, so we are dealing with a given type of minimum and maximum values ​​must be careful is careful more careful oh. If the floating point storage is small (e.g., close to zero), which causes underflow. It Java will nearly zero, so generally do not consider the issue of overflow down Oh.

Common Mistakes three: Variable type selection

Here Insert Picture DescriptionHere Insert Picture Description
As above, when two numbers are integers, the result is an integer, the fractional part is truncated; wherein when a floating point number, a floating point result. As the case may be, to select the appropriate variable type is calculated.

Added:
1, after the process of writing code statement forget to add a semicolon
2, Java punctuation symbols used are in English, does not allow Chinese symbol
3, the process of writing code must pay attention to the correct format oh premise, proper pursuit of beauty.

Released eight original articles · won praise 3 · Views 278

Guess you like

Origin blog.csdn.net/MillionSong/article/details/104190357