From f217fdb1a3b119c89baa81858c4dfdd955e3ace5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E4=BC=9F=E5=B1=B1?= <2609838563@qq.com> Date: Sun, 27 Nov 2022 06:39:46 +0000 Subject: [PATCH 1/6] =?UTF-8?q?rename=2039=20=E5=A7=9C=E4=BC=9F=E5=B1=B1/?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=96=87=E6=9C=AC=E6=96=87=E6=A1=A3.md=20to?= =?UTF-8?q?=2039=20=E5=A7=9C=E4=BC=9F=E5=B1=B1/20221123.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 姜伟山 <2609838563@qq.com> --- .../20221123.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "39 \345\247\234\344\274\237\345\261\261/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.md" => "39 \345\247\234\344\274\237\345\261\261/20221123.md" (100%) diff --git "a/39 \345\247\234\344\274\237\345\261\261/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.md" "b/39 \345\247\234\344\274\237\345\261\261/20221123.md" similarity index 100% rename from "39 \345\247\234\344\274\237\345\261\261/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.md" rename to "39 \345\247\234\344\274\237\345\261\261/20221123.md" -- Gitee From 2dfef754acdae62081fe132e3c983c81d0d467e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E4=BC=9F=E5=B1=B1?= <2609838563@qq.com> Date: Sun, 27 Nov 2022 15:03:20 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20221125/.idea/.gitignore" | 8 ++++++++ .../20221125/.idea/.name" | 1 + .../20221125/.idea/misc.xml" | 6 ++++++ .../20221125/.idea/modules.xml" | 8 ++++++++ .../20221125/.idea/vcs.xml" | 6 ++++++ .../20221125/src/Main.java" | 5 +++++ .../20221125/untitled.iml" | 11 +++++++++++ 7 files changed, 45 insertions(+) create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" new file mode 100644 index 0000000..35410ca --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" new file mode 100644 index 0000000..002da1d --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" @@ -0,0 +1 @@ +Main.java \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" new file mode 100644 index 0000000..0548357 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" new file mode 100644 index 0000000..3007dae --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" "b/39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" new file mode 100644 index 0000000..3e59c38 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file -- Gitee From e2198e5c8b0e5d549c1db78a9302020db061e1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E4=BC=9F=E5=B1=B1?= <2609838563@qq.com> Date: Sun, 27 Nov 2022 07:04:22 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2039?= =?UTF-8?q?=20=E5=A7=9C=E4=BC=9F=E5=B1=B1/20221125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20221125/.idea/.gitignore" | 8 -------- .../20221125/.idea/.name" | 1 - .../20221125/.idea/misc.xml" | 6 ------ .../20221125/.idea/modules.xml" | 8 -------- .../20221125/.idea/vcs.xml" | 6 ------ .../20221125/src/Main.java" | 5 ----- .../20221125/untitled.iml" | 11 ----------- 7 files changed, 45 deletions(-) delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" delete mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" deleted file mode 100644 index 35410ca..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.gitignore" +++ /dev/null @@ -1,8 +0,0 @@ -# 默认忽略的文件 -/shelf/ -/workspace.xml -# 基于编辑器的 HTTP 客户端请求 -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" deleted file mode 100644 index 002da1d..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/.name" +++ /dev/null @@ -1 +0,0 @@ -Main.java \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" deleted file mode 100644 index 0548357..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/misc.xml" +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" deleted file mode 100644 index 3007dae..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/modules.xml" +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" deleted file mode 100644 index b2bdec2..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/.idea/vcs.xml" +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" "b/39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" deleted file mode 100644 index 3e59c38..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/src/Main.java" +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" "b/39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" deleted file mode 100644 index c90834f..0000000 --- "a/39 \345\247\234\344\274\237\345\261\261/20221125/untitled.iml" +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file -- Gitee From ef56fa105a8d659a251f8aa64b1d402b496c1358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E4=BC=9F=E5=B1=B1?= <2609838563@qq.com> Date: Sun, 27 Nov 2022 15:23:46 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20221127/.idea/.gitignore" | 8 ++++++++ .../20221127/.idea/.name" | 1 + .../20221127/.idea/misc.xml" | 6 ++++++ .../20221127/.idea/modules.xml" | 8 ++++++++ .../20221127/.idea/vcs.xml" | 6 ++++++ .../20221127/a20221127.iml" | 11 +++++++++++ .../a20221127/\344\275\234\344\270\232.class" | Bin 0 -> 933 bytes .../20221127/src/\344\275\234\344\270\232.java" | 10 ++++++++++ 8 files changed, 50 insertions(+) create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.gitignore" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.name" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/.idea/misc.xml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/.idea/modules.xml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/.idea/vcs.xml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/a20221127.iml" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/out/production/a20221127/\344\275\234\344\270\232.class" create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/src/\344\275\234\344\270\232.java" diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.gitignore" "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.gitignore" new file mode 100644 index 0000000..35410ca --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.gitignore" @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.name" "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.name" new file mode 100644 index 0000000..9ea30d1 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/.name" @@ -0,0 +1 @@ +作业.java \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/misc.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/misc.xml" new file mode 100644 index 0000000..0548357 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/misc.xml" @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/modules.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/modules.xml" new file mode 100644 index 0000000..f2f167e --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/modules.xml" @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/vcs.xml" "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/vcs.xml" new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/.idea/vcs.xml" @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/a20221127.iml" "b/39 \345\247\234\344\274\237\345\261\261/20221127/a20221127.iml" new file mode 100644 index 0000000..c90834f --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/a20221127.iml" @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/out/production/a20221127/\344\275\234\344\270\232.class" "b/39 \345\247\234\344\274\237\345\261\261/20221127/out/production/a20221127/\344\275\234\344\270\232.class" new file mode 100644 index 0000000000000000000000000000000000000000..1cc41b4b73b8c0cf4819461430c1e11912dcf2d0 GIT binary patch literal 933 zcmZuwNpI6Y6#gcQ?WBeTrwf#ptt?K`HY{aLX~iN?P*|j(N{Ew_j8a#L6FCkNw}Ql( z8wV62PCalbAV{Oq@&ouC2?~D#@y0F$NPT$o<}LGm@0;vVd4rB3X;N|4r2zh3Q}ToTEQ6^XJwpYkmgOxbQT!=dVGl?aHCq}43Vs9 z@q3L*p4$(Ne3>FzwpuXCONMQV{Z268ESq%(CEM9RfP)Dhby%^=sEMv+^NKpW_$w8M?UGPjAejw8*ca2z9pK zes8XJ+b>jH#uXW974x{tpn6b0nybCFXQG8flsfHqz0Yri<0`@s?PJ`}ukZp5_g5(Q zwC?Zr!b}3pJt--_w*atT~OjdG( z1V+B<6<`!&vqER`cJDMixFI@CCs~8<3JM$eKcCS~wvxEreSb z>Q`tg1t(kBqwW2Z?K2oB4xsY|f<%8v2r`mTkRea7N_fZ^$3eI5HYPAhyd>PjA@Y1w QcMXSegic^Iz8L)2FDF&u6#xJL literal 0 HcmV?d00001 diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/src/\344\275\234\344\270\232.java" "b/39 \345\247\234\344\274\237\345\261\261/20221127/src/\344\275\234\344\270\232.java" new file mode 100644 index 0000000..4491cba --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/src/\344\275\234\344\270\232.java" @@ -0,0 +1,10 @@ +public class 作业 { + public static void main(String[] args) { + String student = "小强"; + String teacher = "肖导"; + int number = 15; + + System.out.println(student+"说"+teacher+"你最帅"); + System.out.println("作业需要"+number+"个赞"); + } +} -- Gitee From db742a8aa636ec00f46b01df041962145e5ee19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E4=BC=9F=E5=B1=B1?= <2609838563@qq.com> Date: Sun, 27 Nov 2022 15:28:12 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...72\347\241\200\350\257\255\346\263\225.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221127/20221125 \345\255\246\344\271\240IDEA\345\222\214\345\237\272\347\241\200\350\257\255\346\263\225.md" diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221127/20221125 \345\255\246\344\271\240IDEA\345\222\214\345\237\272\347\241\200\350\257\255\346\263\225.md" "b/39 \345\247\234\344\274\237\345\261\261/20221127/20221125 \345\255\246\344\271\240IDEA\345\222\214\345\237\272\347\241\200\350\257\255\346\263\225.md" new file mode 100644 index 0000000..cede118 --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221127/20221125 \345\255\246\344\271\240IDEA\345\222\214\345\237\272\347\241\200\350\257\255\346\263\225.md" @@ -0,0 +1,54 @@ +# 第二次作业 + +## IDEA中 的配置和快捷键 + +1.配置分为 项目——模块——包——类 + +2.操作步骤 打开IDEN新建项目 找到java模块1.8版本使用新窗口 + +3.找到新建项目包 如果新建包域名要反着写如:net.mxdxstudent 在新建类 + +4.快捷键注释 1.//(单行注释)2./* (多行注释 )*/ 3./**(文档注释)* */ + +5.常用快速命令 main方法:main或psvm, 回车 输出方法:sout,回车 + +6.常用快捷键 + + 1.ctrl+d 复制 2.ctrl+x 剪切 3.ctrl+alt+l 格式化 4.ctrl+/ 单行注释 5.ctrl+shift+/ 选中代码多行注释 + +## 基础语法 + +1.语法分为 字面量 数据类型 变量 关键字 标识符 + +2.字面量类型 1.字符串字面量 2.整数字面量 3.小数字面量 4.字符字面量 5.布尔字面量 + +3.基础代码 1.字符串 string name ("") 2.字符字 int age 36, 3.整数 char gender ‘ ’ ;4.小数 都变了Temprature=36.2 5.布尔 boolean flag=t/f + +4.数字整数和浮点数默认是 int / double + + 5.变量定义 数据类型 变量名 =变量值; 如 int price =998; (变量值 可存入内存在输出改变 int price = 变量值) + +6.变量名不能重复 变量为负值不能使用 定义long类型变量 ,数据后面加L 定义float类型变量,数据后面加F + +7.标识符 1.不能以数字开头 2.不能是关键字 3.要区分大小写 + +8.标识符可以以大小驼峰命名 小驼峰可以命名 方法和变量 大驼峰命名类 + + + +## 作业 + +```java +public class xiaolang { + public static void main(String[] args) { + System.out.println("我爱3班,我尊敬肖导"); + String studentName = "唐国亮"; + String teacherName = "肖俊老师"; + System.out.println(teacherName + "说"); + System.out.println("同学们好"); + System.out.println(studentName + "说"); + System.out.println("肖俊老师担任课程教师,认真负责,有很强的敬业精神,和蔼可亲,幽默风趣,课堂气氛十分活跃,讲课有特色,很受学生欢迎"); + } +} +``` + -- Gitee From 09da506b0bce01a3ee47bd8dee873f677ce60e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E4=BC=9F=E5=B1=B1?= <2609838563@qq.com> Date: Wed, 30 Nov 2022 18:17:58 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...72\347\241\200\350\257\255\346\263\225.md" | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 "39 \345\247\234\344\274\237\345\261\261/20221128 Java\345\237\272\347\241\200\350\257\255\346\263\225.md" diff --git "a/39 \345\247\234\344\274\237\345\261\261/20221128 Java\345\237\272\347\241\200\350\257\255\346\263\225.md" "b/39 \345\247\234\344\274\237\345\261\261/20221128 Java\345\237\272\347\241\200\350\257\255\346\263\225.md" new file mode 100644 index 0000000..885234c --- /dev/null +++ "b/39 \345\247\234\344\274\237\345\261\261/20221128 Java\345\237\272\347\241\200\350\257\255\346\263\225.md" @@ -0,0 +1,164 @@ + + +# \day02 - Java基础语法 + +## 1 类型转换 + +在Java中,一些数据类型之间是可以相互转换的。分为两种情况:自动类型转换和强制类型转换。 + +### 1.1 隐式转换(自动转换) + +​ 把一个表示数据范围小的数值或者变量赋值给另一个表示数据范围大的变量。这种转换方式是自动的,直接书写即可。例如: + +```java +double num = 10; // 将int类型的10直接赋值给double类型 +System.out.println(num); // 输出10.0 +``` + +​ 类型从小到大关系图: + +​ ![](F:\课件\2img\图片1.png) + +说明: + +1. 整数默认是int类型,byte、short和char类型数据参与运算均会自动转换为int类型。 + +```java +byte b1 = 10; +byte b2 = 20; +byte b3 = b1 + b2; +// 第三行代码会报错,b1和b2会自动转换为int类型,计算结果为int,int赋值给byte需要强制类型转换。 +// 修改为: +int num = b1 + b2; +// 或者: +byte b3 = (byte) (b1 + b2); +``` + +2. boolean类型不能与其他基本数据类型相互转换。 + +### 1.2 强制转换(理解) + +​ 把一个表示数据范围大的数值或者变量赋值给另一个表示数据范围小的变量。 + +​ 强制类型转换格式:目标数据类型 变量名 = (目标数据类型)值或者变量; + +​ 例如: + +```java +double num1 = 5.5; +int num2 = (int) num1; // 将double类型的num1强制转换为int类型 +System.out.println(num2); // 输出5(小数位直接舍弃) +``` + +### 1.3 类型转换案例(理解) + +案例代码: + +```java +byte a = 3; +byte b = 4; +byte c = a + b; //错误。因为两个byte变量相加,会先提升为int类型 +byte d = 3 + 4; //正确。常量优化机制 +``` + +**常量优化机制**: + +​ 在编译时,整数常量的计算会直接算出结果,并且会自动判断该结果是否在byte取值范围内, + +- 在:编译通过 + +- 不在:编译失败 + +## 2. 运算符 + +### 2.1 算术运算符 + +#### 2.1.1 运算符和表达式(了解) + +运算符:对常量或者变量进行操作的符号 + +表达式:用运算符把常量或者变量连接起来符合Java语法的式子就可以称为表达式。 + +​ 不同运算符连接的表达式体现的是不同类型的表达式。 + +举例说明: + +```java +int a = 10; +int b = 20; +int c = a + b; +``` + + +:是运算符,并且是算术运算符。 + + a + b:是表达式,由于+是算术运算符,所以这个表达式叫算术表达式。 a和b称为操作数 + +#### 2.1.2 算术运算符(应用) + +| 符号 | 作用 | 说明 | +| :--: | :--: | ---------------------------- | +| + | 加 | 参看小学一年级 | +| - | 减 | 参看小学一年级 | +| * | 乘 | 参看小学二年级,与“×”相同 | +| / | 除 | 参看小学二年级,与“÷”相同 | +| % | 取余 | 获取的是两个数据做除法的余数 | + +**注意:** + +1. /和%的区别:两者都做除法, + - / 取结果的商, + + - % 取结果的余数。 + +2. 整数操作只能得到整数,要想得到小数,必须有浮点数参与运算。 + +~~~java +int a = 10; +int b = 3; +System.out.println(a / b); // 输出结果 +System.out.println(a % b); // 输出结果 +~~~ + +作业1 摄氏度转华氏度 + +``` java +import java.util.Scanner; + +class g { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("摄氏度"); + int num1 = sc.nextInt(); + int num2 = 9; + int num3 = 5; + int num4 = 32; + System.out.println("华氏度"+(num1*num2/num3+num4)); + } +} + +``` + +作业2 + +```java +import java.util.Scanner; + +public class d { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入数字"); + int a = sc.nextInt(); + int ge = a%10; + int shi = a/10%10; + int bai = a/100%10; + int qian = a/1000; +// + System.out.println(("个位"+ge )+("十位"+shi)+("百位"+bai)+("千位"+qian) ); + + } +} + +``` + + + -- Gitee