当前位置:网站首页>2.2- data type
2.2- data type
2022-07-28 17:52:00 【night_ du】
Constant
Definition
- In the process ⾏ In the process, its value cannot be sent ⽣ change
- Constant means we ⽣ Living ⽤ The numerical , word ⺟ etc.
- Constant ⽆ The law is changed ,⼀ Dan change , Its meaning is also changed
classification
- word ⾯ Value constants
- ⾃ Define constants (⾯ Learn again from the object part )
word ⾯ Classification of value constants
- character constants : ⽤ The content enclosed in single quotation marks ‘a’
- String constant : ⽤ What is enclosed in double quotation marks “abc” “ufc”
- Integer constant : All integers 1 0 3
- ⼩ Number constant : be-all ⼩ Count 1.2
- Boolean Literals : ⽐ More special , Only true and false
- Null constant : null( The array section will talk about )
System.out.println(" Character type constant :" + 'a');
System.out.println(" String type constant :" + "abc");
System.out.println(" Integer constant :" + 1);
System.out.println(" Floating point type constants :" + 12.32);
System.out.println(" Boolean type constants :" + true + "\t" + false);
Variable
Definition
- In the process ⾏ In the process of , Within a certain range, you can send ⽣ change
- in other words , Its value can be changed , At different times , Same as ⼀ Variables can represent different values
- With variables , We make ⽤ Just get up ⾮ Always flexible
- In computer memory ⼀ Block storage space , Is the basic unit for storing data
technological process
Declare variables first , Then assign a value to the variable
Statement ⼀ A variable
data type Variable name ;
Assign values to declared variables
Variable name = value
Declare the entry of variables ⾏ The operation of assignment
data type Variable name = value
Declare multiple variables of the same type and initialize at the same time – It can be disassembled
data type Variable name 1, Variable name 2, Variable name 3, Variable name 4 = valueThe first ⼀ The second assignment operation is called initialization
public static void main(String[] args) {
int n; // Statement int Variable of type ( Only integer ), Unassigned
n = 10; // To the variable n assignment
int m = 20; // Statement int Variable of type , assignment
int x = 1, y = 2, z = 3; // Declare more than one int Variable of type
int a, b, c = 10;
}
data type
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-FMlALZtu-1645533840481)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831142857741.png)]](/img/0c/1211f58607a97973512d7a7274dd53.png)
byte 、 character 、 Character set and encoding method
- Bytes make up characters , Characters are the data we can see
- A character set is a set of characters
- The encoding method is the rule for characters to form a character set
Common coding methods
ASCII code :⼀ Ge Ying ⽂ word ⺟( Regardless of ⼤⼩ Write ) Occupy ⼀ Bytes of space ,⼀ Among them ⽂ Chinese characters occupy two bytes .⼀ individual ⼆ Hexadecimal number
Word sequence , As ⼀ Digital units ,⼀ General 8 position ⼆ Hexadecimal number , Conversion for ⼗ Base number . most ⼩ value 0, most ⼤ value 255. Such as ⼀
individual ASCII Code is ⼀ Bytes .UTF-8 code :⼀ Ge Ying ⽂ The character is equal to ⼀ Bytes ,⼀ Among them ⽂( Including traditional Chinese ) Equal to three bytes .
Unicode code :⼀ Ge Ying ⽂ Equal to two bytes ,⼀ Among them ⽂( Including traditional Chinese ) Equal to two bytes .
Symbol : Britain ⽂ Punctuation ⼀ Bytes , in ⽂ Punctuation takes up two bytes . give an example : Britain ⽂ Full stop “.” Occupy 1 Bytes of ⼤⼩, in ⽂ Full stop “.” Occupy 2
Bytes of ⼤⼩.GBK code ⽅ The formula is medium ⽂ Two bytes , Britain ⽂ Occupy 1 Bytes .
The conversion relationship of information units between different orders of magnitude
1B(byte, byte )= 8 bit;
1KB(Kibibyte, kilobytes )=1024B= 2^10 B;
1MB(Mebibyte, Megabytes , Megabytes , abbreviation “ mega ”)=1024KB= 2^20 B;
1GB(Gigabyte, Gigabyte ,⼗ Gigabytes ,⼜ call “ Gigabit ”)=1024MB= 2^30 B;
Basic data type
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-TWcwUx83-1645533840482)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831144316675.png)]](/img/30/60031280a82e0696781dd8dfdd03b0.png)
Integer types :
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-J6914Uri-1645533840483)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831144417151.png)]](/img/a7/2be9aeacf5f7775c045d864cc25950.png)
Create basic data type variables :
byte b = 10;
short s = 20;
int i = 30;
long l = 1000000000000L;
double d = 12.22;
float f = 5.1f;
boolean b1=true;
Lack of precision
public static void main(String[] args) {
double a=1.0;
double b=0.9;
System.out.println(a-b);
double c=(1.4-0.5)/0.9;
System.out.println(c);
}
Java The default of medium integer type is int , Floating point type defaults to double , double The accuracy of the ⽐float want ⾼, So if we're going to double Turn into float can
It can cause the problem of losing accuracy . So we're giving float When assigning a variable of type , want ⽤f Indicate the type of value
Use BigDecimal Deal with the lack of accuracy :
BigDecimal b1=new BigDecimal("1.0");
BigDecimal b2=new BigDecimal("0.9");
System.out.println(b1.subtract(b2));
Character type
char Two bytes 0~65535( No negative number )
ASCII: American Standard Code for information exchange
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-0exWUHYS-1645533840484)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831163537936.png)]](/img/b6/a33bb455da6089edc5e50f89553099.png)
- Unicode: In the field of computer science ⼀ Industry standard , Include character set .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-EEaK46pQ-1645533840484)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831163603439.png)]](/img/29/e6b647782084f251d966e2aebb9abd.png)
public class CharDemo {
public static void main(String[] args) {
//Acsll code
char a = 97;
System.out.println(a);
//Unicode
char b='\u4f01';
System.out.println(b);
}
}
Boolean type
Type conversion
Automatic type conversion
Assign a value or variable representing a small data range to another variable representing a large data range
Cast
Assign a value or variable representing a large data range to another variable representing a small data range
Format : Target data type Variable name =( Target data type ) Values or variables ;
Example :int k =(int)88.88;
public class TypeTranslateDemo {
public static void main(String[] args) {
// Automatic conversion
byte b = 10;
int i = b;
System.out.println(i);
// Strong go
int x = 5;
byte y = (byte) x;
System.out.println(y);
}
}
边栏推荐
- Three ways to dynamically call WebService.Net
- Openpcd安装过程记录
- [p5.js] actual copy - chess board
- 点云处理---二叉树
- [p5.js learning notes] basic knowledge of code drawing
- 【p5.js】实战练习——无规则对称
- Database performance analysis and optimization (internal training materials of Aite future team)
- ROS系统安装
- 关于非递归和递归分别实现求第n个斐波那契数
- Collection集合
猜你喜欢

How to bind idea with code cloud

如何使用IDEA将项目上传到码云
![[unity] three pictures let you understand the shadergraph editor](/img/06/cbb9fc84f17fe8682ffd05e02939c3.png)
[unity] three pictures let you understand the shadergraph editor

ps快速制作全屏水印

编译原理学习笔记1(编译原理概述与词法分析)

进程、线程、信号量和互斥锁

Please make sure you have the correct access rights and the repository exists.
![[unity] how to play sprite Jiugongge?](/img/cf/112a048c0bb335d058806dd5604d10.png)
[unity] how to play sprite Jiugongge?

【C语言必看】哟写BUG呢,我敢保证你踩过坑

如何安装ps的滤镜插件
随机推荐
编译原理学习笔记3(自上而下语法分析)
2021 National Undergraduate data statistics and Analysis Competition
【Unity】Timeline学习笔记(七):自定义片段(Clip)
图像处理代码整理
PyTorch中grid_sample的使用方法
Use of multithreading
[p5.js] practical exercise - irregular symmetry
The solution to the problem that the computer cannot be charged
@Detailed explanation of requestmapping
数字滤波器(四)--模拟滤波器转化为数字滤波器
【Unity FPS】教程 | 使用Unity制作第一人称角色控制器
【Unity】Sprite九宫格到底怎么玩?
How to bind idea with code cloud
Alibaba P8 architect talk: seven knowledge points (including interview questions) that must be learned well to become an architect
mmdetection3D---(1)
How to install PS filter plug-in
[阅读笔记] For:Object Detection with Deep Learning: The Definitive Guide
Students' 20 R language exercises
Visual object class introduces Pascal VOC dataset
leetcode系统性刷题(四)-----哈希表与字符串