From 147f5dce0be1153ccb12c953be3ded53ad0c529a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 21:52:37 +0800 Subject: [PATCH 01/21] =?UTF-8?q?20221125java=E7=AC=AC=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E8=AF=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\344\272\214\346\254\241\350\257\276.md" | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/20221125java\347\254\254\344\272\214\346\254\241\350\257\276.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/20221125java\347\254\254\344\272\214\346\254\241\350\257\276.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221125java\347\254\254\344\272\214\346\254\241\350\257\276.md" new file mode 100644 index 0000000..d5765e7 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221125java\347\254\254\344\272\214\346\254\241\350\257\276.md" @@ -0,0 +1,107 @@ +Java第二次课 + +一、IDEA的说明及安装 + +1、IDEA:全称Intellij IDEA,是用于Java语言开发的集成环境,是业界公认的目前用于Java程序开发最好的工具集成环境:把代码编写,编译,运行,调试等多种功能综合到一起的开发工具 + +2、建议下载破解版官方太贵买不起 + +官方链接:https://www.jetbrains.com/idea + +二、怎样使用此软件运行项目 + +①新建一个空项目(javase_code) + +②新建一个新模块(idea_test) + +③在idea_test模块的src下新建一个包(com.mxdx) + +④在com.mxdx包下新建一个类(HelloWorld) + +⑤在HelloWorld类中编写代码(main回车,sout回车) + +⑥在IDEA中运行HelloWorld + +三、**注释的使用** + +1. //此为单行注释 +2. /* */此为多行注释 +3. /** */此为文档注释 + +四、快捷键的使用 + +1.快速生成main方法和输出语句main方法: + +main或者psvm,回车 + +输出语句:sout,回车 + +2.常用快捷键 + +Ctrl+D:复制数据到下一行 + +Ctrl+X:剪切数据 + +可以用来删除所在行Ctrl+Alt+L:格式化代码,建议自己写代码的时候就注意格式 + +Ctrl+/:对选中的代码添加单行注释如果想取消注释,再来一次即可 + +Ctrl+Shift+/:对选中的代码添加多行注释,如果想取消注释,再来一次 + +java的基础语法 + +一、数据类型 + + + +![](C:\Users\春风\Desktop\photo\zzz\微信图片_20221126200807.png) + +二、变量 + +1.格式:数据类型 变量名 = 变量值; + +范例:int price = 998; + +2.变量的注意事项 + +- 量名不能重复定义 +- 变量未赋值不能使用 +- 定义long类型,变量数据后面加L定义float类型变量 +- 数据后面加F + +三、关键字 + +1.关键字:就是被Java语言赋予了特定含义的单词 + +2.关键字特点: + +- 关键字的字母全部小 +- 写常用的代码编辑器,针对关键字有特殊的颜色标记,非常直观 + +四、标识符 + +1.组成规则 + +由数字、字母、下划线(_)和美元符($)组成 + +2.注意事项 + +不能以数字开头不能是关键字区分大小写 + +3、命名约定 + +小驼峰命名法:方法、变量 + +- 约定1:标识符一个单词的时候,首字母小写范例1:name +- 约定2:标识符是多个单词的时候,第一个单词首字母小写,其他单词首字母大写 +- 范例2:firstName + +大驼峰命名法:类 + +- 约定1:标识符一个单词的时候,首字母大写范例1:Hello +- 约定2:标识符是多个单词的时候,每个单词首字母大写 +- 范例2:HelloWorld + + 作业: + + \ No newline at end of file -- Gitee From 0c8946b0d79ee918293f808481f4053882670c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:11:58 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E6=88=91=E7=9A=84=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\223\276\346\216\245.md" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" new file mode 100644 index 0000000..28be16b --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" @@ -0,0 +1 @@ +载地址:https://registry.npmmirror.com/-/binary/git-for-windows/v2.38.1.windows.1/Git-2.38.1-64-bit.exe \ No newline at end of file -- Gitee From 5f0b5c2ae4b65414e0882c76bd00b73c7d705e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Sat, 26 Nov 2022 14:21:45 +0000 Subject: [PATCH 03/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/=E9=93=BE=E6=8E=A5.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\223\276\346\216\245.md" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" deleted file mode 100644 index 28be16b..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" +++ /dev/null @@ -1 +0,0 @@ -载地址:https://registry.npmmirror.com/-/binary/git-for-windows/v2.38.1.windows.1/Git-2.38.1-64-bit.exe \ No newline at end of file -- Gitee From ecaeaf60a4c355f873f4463a62cf4fc2a643cc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:24:00 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E7=88=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" | 1 + .../\351\223\276\346\216\245.md" | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" new file mode 100644 index 0000000..6e2d419 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" @@ -0,0 +1 @@ +love \ No newline at end of file diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" deleted file mode 100644 index 28be16b..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\351\223\276\346\216\245.md" +++ /dev/null @@ -1 +0,0 @@ -载地址:https://registry.npmmirror.com/-/binary/git-for-windows/v2.38.1.windows.1/Git-2.38.1-64-bit.exe \ No newline at end of file -- Gitee From e171214dc7bfb1e500915dade3f0d017021e7e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:32:16 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E6=98=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" new file mode 100644 index 0000000..e69de29 -- Gitee From 5592b6af7ed7bac4fbab363ef5986bdf19bf1f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Sat, 26 Nov 2022 14:33:07 +0000 Subject: [PATCH 06/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/=E6=96=B0=E5=BB=BA=20?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=96=87=E6=A1=A3.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" deleted file mode 100644 index e69de29..0000000 -- Gitee From b0c82df940698d8020c33450301d53669ef53711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:34:42 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E6=B4=8B=E6=B5=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" | 1 - .../you.md" | 0 2 files changed, 1 deletion(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" rename "30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" => "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" (100%) diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" deleted file mode 100644 index 6e2d419..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/love.md" +++ /dev/null @@ -1 +0,0 @@ -love \ No newline at end of file diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" similarity index 100% rename from "30\345\217\267\350\256\270\346\201\251\346\260\221/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" rename to "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" -- Gitee From fb116f71d511034c2b7001ad9b4e8dad9cc525a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:41:18 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E7=AC=AC=E4=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" index e69de29..0615319 100644 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" @@ -0,0 +1 @@ +fdsfdsfsfd \ No newline at end of file -- Gitee From 665f1e08bc515eac09b8d0b8eeb075de6c4ee33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:44:58 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E7=AC=AC=E5=9B=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" index 0615319..4dbd357 100644 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" @@ -1 +1,3 @@ -fdsfdsfsfd \ No newline at end of file +fdsfdsfsfd + +kkks \ No newline at end of file -- Gitee From 65abd9ec5b379c59d5cab233abbbc6339d37ce12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Sat, 26 Nov 2022 14:45:52 +0000 Subject: [PATCH 10/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/you.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" deleted file mode 100644 index 4dbd357..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" +++ /dev/null @@ -1,3 +0,0 @@ -fdsfdsfsfd - -kkks \ No newline at end of file -- Gitee From a7bc2a7b3d54d9ac096f14928e9ede2e4b640559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:47:02 +0800 Subject: [PATCH 11/21] 666 --- "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" | 1 + "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" new file mode 100644 index 0000000..ce64560 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" @@ -0,0 +1 @@ +9999999 \ No newline at end of file diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" deleted file mode 100644 index 4dbd357..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/you.md" +++ /dev/null @@ -1,3 +0,0 @@ -fdsfdsfsfd - -kkks \ No newline at end of file -- Gitee From 452ed2aa46609e59193bebcef0ff8b15482bc24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 22:48:50 +0800 Subject: [PATCH 12/21] 666 --- "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" index ce64560..3868f8c 100644 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" @@ -1 +1 @@ -9999999 \ No newline at end of file +9999999xcxcx \ No newline at end of file -- Gitee From 88f822bf11d7e8362bebfb560a4de0ece1d341b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Sat, 26 Nov 2022 14:49:42 +0000 Subject: [PATCH 13/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/666.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" deleted file mode 100644 index 3868f8c..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" +++ /dev/null @@ -1 +0,0 @@ -9999999xcxcx \ No newline at end of file -- Gitee From 684426d950aa14a64c7e2e97b28fa6d967d729cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 23:23:12 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" | 1 - .../\344\270\213\350\275\275\351\223\276\346\216\245.md" | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" deleted file mode 100644 index 3868f8c..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/666.md" +++ /dev/null @@ -1 +0,0 @@ -9999999xcxcx \ No newline at end of file diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" new file mode 100644 index 0000000..988da03 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" @@ -0,0 +1,2 @@ +下载链接: +https://www.yuque.com/docs/share/1f41691e-39d8-4e9f-8d70-0c9c84d2dd0a?# 《Typora》 \ No newline at end of file -- Gitee From f084b687497696df8817d4c2e7529956a4346212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 23:24:36 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\270\213\350\275\275\351\223\276\346\216\245.md" | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" index 988da03..98bf2ed 100644 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" @@ -1,2 +1,4 @@ 下载链接: -https://www.yuque.com/docs/share/1f41691e-39d8-4e9f-8d70-0c9c84d2dd0a?# 《Typora》 \ No newline at end of file +https://www.yuque.com/docs/share/1f41691e-39d8-4e9f-8d70-0c9c84d2dd0a?# 《Typora》 + +​ \ No newline at end of file -- Gitee From cfbba6e8f9162b0c27e0b548f139a8740058aef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080@qq.com> Date: Sat, 26 Nov 2022 23:30:15 +0800 Subject: [PATCH 16/21] html --- .../html.md" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" new file mode 100644 index 0000000..5291421 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" @@ -0,0 +1,79 @@ +```html + + + + + + + Document + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
课程表
上午星期一星期二星期三星期四星期五
习近平思想专业课道德与法治专业课英语
数学
下午体育没课习近平思想没课专业课
+ + +``` + -- Gitee From 605bafa580313761626c64b6770b06bde2066c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Sun, 27 Nov 2022 06:07:44 +0000 Subject: [PATCH 17/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=93=BE=E6=8E=A5.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\270\213\350\275\275\351\223\276\346\216\245.md" | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" deleted file mode 100644 index 98bf2ed..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/\344\270\213\350\275\275\351\223\276\346\216\245.md" +++ /dev/null @@ -1,4 +0,0 @@ -下载链接: -https://www.yuque.com/docs/share/1f41691e-39d8-4e9f-8d70-0c9c84d2dd0a?# 《Typora》 - -​ \ No newline at end of file -- Gitee From 4d14a9639c535c595c9e5c035348c80a6129e5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Sun, 27 Nov 2022 06:07:51 +0000 Subject: [PATCH 18/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/html.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../html.md" | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" deleted file mode 100644 index 5291421..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/html.md" +++ /dev/null @@ -1,79 +0,0 @@ -```html - - - - - - - Document - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
课程表
上午星期一星期二星期三星期四星期五
习近平思想专业课道德与法治专业课英语
数学
下午体育没课习近平思想没课专业课
- - -``` - -- Gitee From fbe3b385aa877b408e3478c49091bce478c25413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080qq.com> Date: Tue, 29 Nov 2022 20:26:58 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=20=E7=AC=AC=E4=B8=89=E6=AC=A1=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\254\344\270\211\346\254\241\350\257\276" | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" new file mode 100644 index 0000000..ef1c772 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" @@ -0,0 +1,241 @@ +java第三次课 + +一. + +数据类型转换 + +1.0 隐式转换(自动转换) + +把一个表示数据范围小的数值或者变量赋值给另一个表示数据范围大的变量。这种转换方式是自动的,直接书写即可。 + +```java +double num = 10; // 将int类型的10直接赋值给double类型 +System.out.println(num); // 输出10.0 +``` + +类型从小到大关系图: + +​ ![](E:\java内容\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.1强制转换(理解) + +​ 把一个表示数据范围大的数值或者变量赋值给另一个表示数据范围小的变量。 + +​ 强制类型转换格式:目标数据类型 变量名 = (目标数据类型)值或者变量; + +```java +double num1 = 5.5; +int num2 = (int) num1; // 将double类型的num1强制转换为int类型 +System.out.println(num2); // 输出5(小数位直接舍弃) +``` + +1. 2类型转换案例(理解) + + ```java + byte a = 3; + byte b = 4; + byte c = a + b; //错误。因为两个byte变量相加,会先提升为int类型 + byte d = 3 + 4; //正确。常量优化机制 + ``` + + **常量优化机制**: + + ​ 在编译时,整数常量的计算会直接算出结果,并且会自动判断该结果是否在byte取值范围内, + + - 在:编译通过 + - 不在:编译失败 + +二.运算符 + +2.1 算术运算符2.1.1 运算符和表达式(了解) + +运算符:对常量或者变量进行操作的符号 + +表达式:用运算符把常量或者变量连接起来符合Java语法的式子就可以称为表达式。 + +​ 不同运算符连接的表达式体现的是不同类型的表达式。 + +举例说明: + +```Java +int a = 10; +int b = 20; +int c = a + b; +``` + + +:是运算符,并且是算术运算符。 + + a + b:是表达式,由于+是算术运算符,所以这个表达式叫算术表达式。 a和b称为操作数 + +**注意:** + +1. /和%的区别:两者都做除法, + + - / 取结果的商, + + - % 取结果的余数。 + +2. 整数操作只能得到整数,要想得到小数,必须有浮点数参与运算 + +3. char类型参与算术运算,使用的是计算机底层对应的十进制数值。需要我们记住三个字符对应的数值: + + 'a' -- 97 a-z是连续的,所以'b'对应的数值是98,'c'是99,依次递加 + + 'A' -- 65 A-Z是连续的,所以'B'对应的数值是66,'C'是67,依次递加 + + '0' -- 48 0-9是连续的,所以'1'对应的数值是49,'2'是50,依次递加 + + + +```java +// 可以通过使用字符与整数做算术运算,得出字符对应的数值是多少 +char ch1 = 'a'; +System.out.println(ch1 + 1); // 输出98,97 + 1 = 98 + +char ch2 = 'A'; +System.out.println(ch2 + 1); // 输出66,65 + 1 = 66 + +char ch3 = '0'; +System.out.println(ch3 + 1); // 输出49,48 + 1 = 49 +``` + +算术表达式中包含不同的基本数据类型的值的时候,整个算术表达式的类型会自动进行提升。 + +``` +1. byte类型,short类型和char类型将被提升到int类型,不管是否有其他类型参与运算。 +2. 整个表达式的类型自动提升到与表达式中最高等级的操作数相同的类型 +3. 等级顺序:byte,short,char --> int --> long --> float --> double +``` + +例如 + +``` +byte b1 = 10; +byte b2 = 20; +// byte b3 = b1 + b2; // 该行报错,因为byte类型参与算术运算会自动提示为int,int赋值给byte可能损失精度 +int i3 = b1 + b2; // 应该使用int接收 +byte b3 = (byte) (b1 + b2); // 或者将结果强制转换为byte类型 +------------------------------- +int num1 = 10; +double num2 = 20.0; +double num3 = num1 + num2; // 使用double接收,因为num1会自动提升为double类型 +``` + +#### 2.1.4 字符串的“+”操作(理解) + +当“+”操作中出现字符串时,这个”+”是字符串连接符,而不是算术运算。【+号的左右两边任意一边出现字符串,那这个就个拼接符】 + +当+号是拼接符的时候。得到的结果,也是字符串 + +```java +System.out.println("qiuqiu"+ 666); // 输出:qiuqiu666 +``` + +在”+”操作中,如果出现了字符串,就是连接运算符,否则就是算术运算。当连续进行“+”操作时,从左到右逐个执行。 + +``` +System.out.println(1 + 99 + "年白酒"); // 输出:100年白酒 +System.out.println(1 + 2 + "兔子" + 3 + 4); // 输出:3兔子34 // 只要前面有字符串,后面都被污染成字符串 +// 可以使用小括号改变运算的优先级 +System.out.println(1 + 2 + "兔子" + (3 + 4)); // 输出:3兔子7 +``` + +二.键盘录入 + +我们可以通过 Scanner 类来获取用户的输入。使用步骤如下: + +1、导包。Scanner 类在java.util包下,所以需要将该类导入。导包的语句需要定义在类的上面。 + +```java +import java.util.Scanner; +``` + +2.创建scanner对象 + +```java +Scanner sc = new Scanner(System.in);// 创建Scanner对象,sc表示变量名,其他均不可变 +``` + +3.接收数据 + +```java +int i = sc.nextInt(); // 表示将键盘录入的值作为int数返回。 +``` + +示例 + +```java +import java.util.Scanner; +public class ScannerDemo { + public static void main(String[] args) { + //创建对象 + Scanner sc = new Scanner(System.in); + //接收数据 + int a = sc.nextInt(); + //输出数据 + System.out.println(a); + } +} +``` + +作业一:获取四位数的个位,十位,百位和千位 + +```java +public class sss { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); //创建键盘输入对象 + int number; //输入int类型的正整数 + System.out.print("请输入一个任意四位正整数:"); + number = sc.nextInt(); + int a,b,c,d; + a = number/1000; + b = (number-1000*a)/100; + c = ((number-1000*a)-100*b)/10; + d = ((number-1000*a)-100*b)-10*c; + System.out.println(a); + System.out.println(b); + System.out.println(c); + System.out.println(d); + } +} +``` + +作业二: + +```java + public class hhhh { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入华氏温度:"); + int number = scanner.nextInt(); + int a; + a = (number - 32) * 5 / 9; + System.out.println("摄氏温度;" + a); + + System.out.println("请输入摄氏温度:"); + int b = scanner.nextInt(); + b = b * 9 / 5 + 33; + System.out.println("华氏温度:" + b); + + } +} +``` + +​ 2022.11.29 \ No newline at end of file -- Gitee From bc105574dc39649928f33615a38205f402777d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <12073458+xu-enmin@user.noreply.gitee.com> Date: Tue, 29 Nov 2022 12:36:02 +0000 Subject: [PATCH 20/21] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2030?= =?UTF-8?q?=E5=8F=B7=E8=AE=B8=E6=81=A9=E6=B0=91/20221129java=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=AC=A1=E8=AF=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\254\344\270\211\346\254\241\350\257\276" | 241 ------------------ 1 file changed, 241 deletions(-) delete mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" deleted file mode 100644 index ef1c772..0000000 --- "a/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276" +++ /dev/null @@ -1,241 +0,0 @@ -java第三次课 - -一. - -数据类型转换 - -1.0 隐式转换(自动转换) - -把一个表示数据范围小的数值或者变量赋值给另一个表示数据范围大的变量。这种转换方式是自动的,直接书写即可。 - -```java -double num = 10; // 将int类型的10直接赋值给double类型 -System.out.println(num); // 输出10.0 -``` - -类型从小到大关系图: - -​ ![](E:\java内容\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.1强制转换(理解) - -​ 把一个表示数据范围大的数值或者变量赋值给另一个表示数据范围小的变量。 - -​ 强制类型转换格式:目标数据类型 变量名 = (目标数据类型)值或者变量; - -```java -double num1 = 5.5; -int num2 = (int) num1; // 将double类型的num1强制转换为int类型 -System.out.println(num2); // 输出5(小数位直接舍弃) -``` - -1. 2类型转换案例(理解) - - ```java - byte a = 3; - byte b = 4; - byte c = a + b; //错误。因为两个byte变量相加,会先提升为int类型 - byte d = 3 + 4; //正确。常量优化机制 - ``` - - **常量优化机制**: - - ​ 在编译时,整数常量的计算会直接算出结果,并且会自动判断该结果是否在byte取值范围内, - - - 在:编译通过 - - 不在:编译失败 - -二.运算符 - -2.1 算术运算符2.1.1 运算符和表达式(了解) - -运算符:对常量或者变量进行操作的符号 - -表达式:用运算符把常量或者变量连接起来符合Java语法的式子就可以称为表达式。 - -​ 不同运算符连接的表达式体现的是不同类型的表达式。 - -举例说明: - -```Java -int a = 10; -int b = 20; -int c = a + b; -``` - - +:是运算符,并且是算术运算符。 - - a + b:是表达式,由于+是算术运算符,所以这个表达式叫算术表达式。 a和b称为操作数 - -**注意:** - -1. /和%的区别:两者都做除法, - - - / 取结果的商, - - - % 取结果的余数。 - -2. 整数操作只能得到整数,要想得到小数,必须有浮点数参与运算 - -3. char类型参与算术运算,使用的是计算机底层对应的十进制数值。需要我们记住三个字符对应的数值: - - 'a' -- 97 a-z是连续的,所以'b'对应的数值是98,'c'是99,依次递加 - - 'A' -- 65 A-Z是连续的,所以'B'对应的数值是66,'C'是67,依次递加 - - '0' -- 48 0-9是连续的,所以'1'对应的数值是49,'2'是50,依次递加 - - - -```java -// 可以通过使用字符与整数做算术运算,得出字符对应的数值是多少 -char ch1 = 'a'; -System.out.println(ch1 + 1); // 输出98,97 + 1 = 98 - -char ch2 = 'A'; -System.out.println(ch2 + 1); // 输出66,65 + 1 = 66 - -char ch3 = '0'; -System.out.println(ch3 + 1); // 输出49,48 + 1 = 49 -``` - -算术表达式中包含不同的基本数据类型的值的时候,整个算术表达式的类型会自动进行提升。 - -``` -1. byte类型,short类型和char类型将被提升到int类型,不管是否有其他类型参与运算。 -2. 整个表达式的类型自动提升到与表达式中最高等级的操作数相同的类型 -3. 等级顺序:byte,short,char --> int --> long --> float --> double -``` - -例如 - -``` -byte b1 = 10; -byte b2 = 20; -// byte b3 = b1 + b2; // 该行报错,因为byte类型参与算术运算会自动提示为int,int赋值给byte可能损失精度 -int i3 = b1 + b2; // 应该使用int接收 -byte b3 = (byte) (b1 + b2); // 或者将结果强制转换为byte类型 -------------------------------- -int num1 = 10; -double num2 = 20.0; -double num3 = num1 + num2; // 使用double接收,因为num1会自动提升为double类型 -``` - -#### 2.1.4 字符串的“+”操作(理解) - -当“+”操作中出现字符串时,这个”+”是字符串连接符,而不是算术运算。【+号的左右两边任意一边出现字符串,那这个就个拼接符】 - -当+号是拼接符的时候。得到的结果,也是字符串 - -```java -System.out.println("qiuqiu"+ 666); // 输出:qiuqiu666 -``` - -在”+”操作中,如果出现了字符串,就是连接运算符,否则就是算术运算。当连续进行“+”操作时,从左到右逐个执行。 - -``` -System.out.println(1 + 99 + "年白酒"); // 输出:100年白酒 -System.out.println(1 + 2 + "兔子" + 3 + 4); // 输出:3兔子34 // 只要前面有字符串,后面都被污染成字符串 -// 可以使用小括号改变运算的优先级 -System.out.println(1 + 2 + "兔子" + (3 + 4)); // 输出:3兔子7 -``` - -二.键盘录入 - -我们可以通过 Scanner 类来获取用户的输入。使用步骤如下: - -1、导包。Scanner 类在java.util包下,所以需要将该类导入。导包的语句需要定义在类的上面。 - -```java -import java.util.Scanner; -``` - -2.创建scanner对象 - -```java -Scanner sc = new Scanner(System.in);// 创建Scanner对象,sc表示变量名,其他均不可变 -``` - -3.接收数据 - -```java -int i = sc.nextInt(); // 表示将键盘录入的值作为int数返回。 -``` - -示例 - -```java -import java.util.Scanner; -public class ScannerDemo { - public static void main(String[] args) { - //创建对象 - Scanner sc = new Scanner(System.in); - //接收数据 - int a = sc.nextInt(); - //输出数据 - System.out.println(a); - } -} -``` - -作业一:获取四位数的个位,十位,百位和千位 - -```java -public class sss { - public static void main(String args[]){ - Scanner sc = new Scanner(System.in); //创建键盘输入对象 - int number; //输入int类型的正整数 - System.out.print("请输入一个任意四位正整数:"); - number = sc.nextInt(); - int a,b,c,d; - a = number/1000; - b = (number-1000*a)/100; - c = ((number-1000*a)-100*b)/10; - d = ((number-1000*a)-100*b)-10*c; - System.out.println(a); - System.out.println(b); - System.out.println(c); - System.out.println(d); - } -} -``` - -作业二: - -```java - public class hhhh { - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - System.out.println("请输入华氏温度:"); - int number = scanner.nextInt(); - int a; - a = (number - 32) * 5 / 9; - System.out.println("摄氏温度;" + a); - - System.out.println("请输入摄氏温度:"); - int b = scanner.nextInt(); - b = b * 9 / 5 + 33; - System.out.println("华氏温度:" + b); - - } -} -``` - -​ 2022.11.29 \ No newline at end of file -- Gitee From bd5ef1709a8ca67d267f87c9d67fd57eec59a52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=A9=E6=B0=91?= <3256972080qq.com> Date: Tue, 29 Nov 2022 20:38:45 +0800 Subject: [PATCH 21/21] =?UTF-8?q?=20=E7=AC=AC=E4=B8=89=E6=AC=A1=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\344\270\211\346\254\241\350\257\276.md" | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 "30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276.md" diff --git "a/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276.md" "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276.md" new file mode 100644 index 0000000..ef1c772 --- /dev/null +++ "b/30\345\217\267\350\256\270\346\201\251\346\260\221/20221129java\347\254\254\344\270\211\346\254\241\350\257\276.md" @@ -0,0 +1,241 @@ +java第三次课 + +一. + +数据类型转换 + +1.0 隐式转换(自动转换) + +把一个表示数据范围小的数值或者变量赋值给另一个表示数据范围大的变量。这种转换方式是自动的,直接书写即可。 + +```java +double num = 10; // 将int类型的10直接赋值给double类型 +System.out.println(num); // 输出10.0 +``` + +类型从小到大关系图: + +​ ![](E:\java内容\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.1强制转换(理解) + +​ 把一个表示数据范围大的数值或者变量赋值给另一个表示数据范围小的变量。 + +​ 强制类型转换格式:目标数据类型 变量名 = (目标数据类型)值或者变量; + +```java +double num1 = 5.5; +int num2 = (int) num1; // 将double类型的num1强制转换为int类型 +System.out.println(num2); // 输出5(小数位直接舍弃) +``` + +1. 2类型转换案例(理解) + + ```java + byte a = 3; + byte b = 4; + byte c = a + b; //错误。因为两个byte变量相加,会先提升为int类型 + byte d = 3 + 4; //正确。常量优化机制 + ``` + + **常量优化机制**: + + ​ 在编译时,整数常量的计算会直接算出结果,并且会自动判断该结果是否在byte取值范围内, + + - 在:编译通过 + - 不在:编译失败 + +二.运算符 + +2.1 算术运算符2.1.1 运算符和表达式(了解) + +运算符:对常量或者变量进行操作的符号 + +表达式:用运算符把常量或者变量连接起来符合Java语法的式子就可以称为表达式。 + +​ 不同运算符连接的表达式体现的是不同类型的表达式。 + +举例说明: + +```Java +int a = 10; +int b = 20; +int c = a + b; +``` + + +:是运算符,并且是算术运算符。 + + a + b:是表达式,由于+是算术运算符,所以这个表达式叫算术表达式。 a和b称为操作数 + +**注意:** + +1. /和%的区别:两者都做除法, + + - / 取结果的商, + + - % 取结果的余数。 + +2. 整数操作只能得到整数,要想得到小数,必须有浮点数参与运算 + +3. char类型参与算术运算,使用的是计算机底层对应的十进制数值。需要我们记住三个字符对应的数值: + + 'a' -- 97 a-z是连续的,所以'b'对应的数值是98,'c'是99,依次递加 + + 'A' -- 65 A-Z是连续的,所以'B'对应的数值是66,'C'是67,依次递加 + + '0' -- 48 0-9是连续的,所以'1'对应的数值是49,'2'是50,依次递加 + + + +```java +// 可以通过使用字符与整数做算术运算,得出字符对应的数值是多少 +char ch1 = 'a'; +System.out.println(ch1 + 1); // 输出98,97 + 1 = 98 + +char ch2 = 'A'; +System.out.println(ch2 + 1); // 输出66,65 + 1 = 66 + +char ch3 = '0'; +System.out.println(ch3 + 1); // 输出49,48 + 1 = 49 +``` + +算术表达式中包含不同的基本数据类型的值的时候,整个算术表达式的类型会自动进行提升。 + +``` +1. byte类型,short类型和char类型将被提升到int类型,不管是否有其他类型参与运算。 +2. 整个表达式的类型自动提升到与表达式中最高等级的操作数相同的类型 +3. 等级顺序:byte,short,char --> int --> long --> float --> double +``` + +例如 + +``` +byte b1 = 10; +byte b2 = 20; +// byte b3 = b1 + b2; // 该行报错,因为byte类型参与算术运算会自动提示为int,int赋值给byte可能损失精度 +int i3 = b1 + b2; // 应该使用int接收 +byte b3 = (byte) (b1 + b2); // 或者将结果强制转换为byte类型 +------------------------------- +int num1 = 10; +double num2 = 20.0; +double num3 = num1 + num2; // 使用double接收,因为num1会自动提升为double类型 +``` + +#### 2.1.4 字符串的“+”操作(理解) + +当“+”操作中出现字符串时,这个”+”是字符串连接符,而不是算术运算。【+号的左右两边任意一边出现字符串,那这个就个拼接符】 + +当+号是拼接符的时候。得到的结果,也是字符串 + +```java +System.out.println("qiuqiu"+ 666); // 输出:qiuqiu666 +``` + +在”+”操作中,如果出现了字符串,就是连接运算符,否则就是算术运算。当连续进行“+”操作时,从左到右逐个执行。 + +``` +System.out.println(1 + 99 + "年白酒"); // 输出:100年白酒 +System.out.println(1 + 2 + "兔子" + 3 + 4); // 输出:3兔子34 // 只要前面有字符串,后面都被污染成字符串 +// 可以使用小括号改变运算的优先级 +System.out.println(1 + 2 + "兔子" + (3 + 4)); // 输出:3兔子7 +``` + +二.键盘录入 + +我们可以通过 Scanner 类来获取用户的输入。使用步骤如下: + +1、导包。Scanner 类在java.util包下,所以需要将该类导入。导包的语句需要定义在类的上面。 + +```java +import java.util.Scanner; +``` + +2.创建scanner对象 + +```java +Scanner sc = new Scanner(System.in);// 创建Scanner对象,sc表示变量名,其他均不可变 +``` + +3.接收数据 + +```java +int i = sc.nextInt(); // 表示将键盘录入的值作为int数返回。 +``` + +示例 + +```java +import java.util.Scanner; +public class ScannerDemo { + public static void main(String[] args) { + //创建对象 + Scanner sc = new Scanner(System.in); + //接收数据 + int a = sc.nextInt(); + //输出数据 + System.out.println(a); + } +} +``` + +作业一:获取四位数的个位,十位,百位和千位 + +```java +public class sss { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); //创建键盘输入对象 + int number; //输入int类型的正整数 + System.out.print("请输入一个任意四位正整数:"); + number = sc.nextInt(); + int a,b,c,d; + a = number/1000; + b = (number-1000*a)/100; + c = ((number-1000*a)-100*b)/10; + d = ((number-1000*a)-100*b)-10*c; + System.out.println(a); + System.out.println(b); + System.out.println(c); + System.out.println(d); + } +} +``` + +作业二: + +```java + public class hhhh { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("请输入华氏温度:"); + int number = scanner.nextInt(); + int a; + a = (number - 32) * 5 / 9; + System.out.println("摄氏温度;" + a); + + System.out.println("请输入摄氏温度:"); + int b = scanner.nextInt(); + b = b * 9 / 5 + 33; + System.out.println("华氏温度:" + b); + + } +} +``` + +​ 2022.11.29 \ No newline at end of file -- Gitee