三、Java变量

1.变量

定义:不名思意就是变化的量。又可以说在程序中会改变的值。

2.变量类型

局部变量:类方法中的变量。
实例变量:方法之外的变量,不需用static修饰。
类变量:方法之外的变量,用static修饰。

3.基本变量数据类型
(1).整型

在这里插入图片描述
int integer = 10;

(2).非整型(浮点型)

在这里插入图片描述
double noInteger = 3.14;
float noInteger2 = 25.5f;

(3).字符型 (char)默认值为’\u0000’—>打印出来是一个空格。Unicode编码

char sex = ‘男’;

(4).布尔型 (boolean) 默认值为false 。 只有两个值:true || false

扫描二维码关注公众号,回复: 6099205 查看本文章

boolean judge = true;

test:

找出下列命名不规范的变量名:simple、$lastname、love you、123rate、discount%、make_money、marks_3、words、Words、int。
simple:正确
l a s t n a m e lastname:正确,但是不规范,可以修改为: lastName
love you:错误,中间有空格。可以修改为:loveYou
123rate:错误,以数字开头,可以修改为:rate123
discount%:错误,有非法字符,可以修改为:discount
make_money:正确
marks_3:正确
words:正确
Words:正确
int:错误,这是一个关键字,可以修改为:Int

猜你喜欢

转载自blog.csdn.net/weixin_42635052/article/details/88726789