官术网_书友最值得收藏!

3.5 Summary

That’s it for data types in Java. Just remember that Java is a strongly typed language. So much so, in fact, that you’ll learn these data types in a big hurry if you use Java very much at all. For those of you coming from a C++ type background, you’ll probably notice right away that Java is even more strongly typed than C++. For example, no more assigning 1 to a boolean variable. In Java, booleans are true or false - nothing else. Most of the information here is probably review/common sense if you’ve done any sort of programming at all. The most important thing for you to get out of this is to remember that Java is strongly typed.

As you will already know a variable is a value in a program which can be changed, this value is then used in some way by the program. For example, if a program were to ask the user for their age then print out how old they would be in 10 years time the program would store the age as a variable and then add 10 to it.

In Java variables are declared with the following syntax(語法):

data_type variable_name;

The data_type can be from the simple types or from user defined types (which will be covered in later tutorials).

The simple types are:

byte, short, int and long. All these types hold integer numbers of varying minimum and maximum sizes.

float and double which hold floating point numbers, again with different minimum and maximum values.

char is used to hold the value of characters.

boolean variables are either true or false.

byte, short, int和long,這些類型都存儲(chǔ)具有不同范圍的最大值和最小值的整數(shù)。

float和double存儲(chǔ)浮點(diǎn)數(shù)字,同樣具有不同的最小值和最大值。

char用來存儲(chǔ)字符的值。

boolean變量為真值或假值。

主站蜘蛛池模板: 开封县| 盐亭县| 和静县| 阳谷县| 合川市| 贵州省| 佛坪县| 遂宁市| 梅州市| 绥化市| 邯郸市| 若尔盖县| 瑞金市| 亚东县| 永胜县| 枣阳市| 宽甸| 咸宁市| 清河县| 华坪县| 长汀县| 皋兰县| 渑池县| 沧源| 民权县| 花莲市| 濮阳市| 彰化市| 景东| 绥中县| 大冶市| 类乌齐县| 吴旗县| 白河县| 通州区| 三江| 收藏| 沙田区| 宜兰县| 兴和县| 唐山市|