Home > Java > javaTutorial > body text

What are the basic data types in Java?

王林
Release: 2023-04-19 16:13:06
forward
1545 people have browsed it

1、整型,byte 、short 、int 、long

byte 的取值范围:-128~127(-2的7次方到2的7次方-1)

short 的取值范围:-32768~32767(-2的15次方到2的15次方-1)

int 的取值范围:-2147483648~2147483647(-2的31次方到2的31次方-1)

long 的取值范围:-9223372036854774808~9223372036854774807(-2的63次方到2的63次方-1)

2、浮点型,float、double

float 和 double 都是表示浮点型的数据类型,它们之间的区别在于精确度的不同。

float(单精度浮点型)取值范围:3.402823e+38~1.401298e-45(e+38 表示乘以10的38次方,而e-45 表示乘以10的负45次方)

double(双精度浮点型)取值范围:1.797693e+308~4.9000000e-324(同上)

3、字符型,char。

char ch = 'a'; // 可以是汉字,因为是Unicode编码
char ch = 1010; // 可以是十进制数、八进制数、十六进制数等等。
char ch = '\0'; // 可以用字符编码来初始化,如:'\0' 表示结束符,它的ascll码是0,这句话的意思和 ch = 0 是一个意思。
Copy after login

4、布尔型,boolean。

取值就两个:true、false。

The above is the detailed content of What are the basic data types in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!