diff --git "a/39 \345\220\264\346\241\220/20230330 Java \350\277\220\347\256\227\347\254\246 \345\217\230\351\207\217\347\261\273\345\236\213\350\275\254\346\215\242.md" "b/39 \345\220\264\346\241\220/20230330 Java \350\277\220\347\256\227\347\254\246 \345\217\230\351\207\217\347\261\273\345\236\213\350\275\254\346\215\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..a1d5e7099a36890a67ce2b8e6e4b1069d99c61f7 --- /dev/null +++ "b/39 \345\220\264\346\241\220/20230330 Java \350\277\220\347\256\227\347\254\246 \345\217\230\351\207\217\347\261\273\345\236\213\350\275\254\346\215\242.md" @@ -0,0 +1,255 @@ +# 笔记: + +#### ctrl + x 删除当前行 + +##### 创建顺序:文件-->模块-->包-->类 + +##### 注释:// 单行注释 + +/* + +*/ 多行注释 + +##### 自动换行注释:/** + +​ */ + +##### 查看一个类型的最小,最大值: + +查看类型的最大值: System.out.println(Short.MAX_VALUE); + +查看类型的最小值: System.out.println(Short.MIN_VALUE); + +第一个为数据类型,首字母大写,其余也严格区分大小写。 + +##### System.out.println(0=='0') + +输出为false,布尔值。 + +#### long a =11111111111(11位)L; + +数字后最好加L, 因为输入整数默认为int int的最大值有11位,则无法正常转换为long 需要加L,强转。 + +#### float b = 4.0F ; + +小数后必须加F,因为小数的默认类型为double,可能会出现:(报错)java: 不兼容的类型: 从double转换到float可能会有损失。 + +#### 标识符: + +由一些字符,符号组合的名称,给类,方法,变量等起名。 + +规则:由数字,字母,下划线,美元符($)组成,不能以数字开头,应以驼峰式写法 如:studyNumber,StudyNumber。 + +#### 类型转换: + +byte 1字节(8位)-->short-->int(4字节,32位)-->long-->float-->double + +​ char/ + +##### 表达式类型转换: + +int=byte+short+char + +byte,short,char相当于int + +在数据类型参与计算时以最高的数据类型为最终数据类型 + +##### 强制类型转换: + +float a =(float) 变量,数据。 + +可能会造成数据丢失,最多装满强转的类型。 + +#### 扫描器(Scanner): + +new Scanner(System.in)+ alt+回车 自动添加前缀(局部变量) + +Scanner sc = new Scanner(System.in); + +如:a=sc.next().charAt(0); + +​ b=sc.nextInt(); + +#### 取余(%): + +4&12 <=> 4/12 = 0---4 取4。 + +小数向大的数取等于它本身。 + +用10取余时,只保护了10中的个位,前面的数都舍去。用100取余同理。 + +#### 逻辑运算符: + +&& ,|| 等 ,如报&&/||,不能应用于’boolean‘,’int‘ ,应注意是否合理添加括号,或符号是否写错(可能以为是把&&/||,当运算符用了) + +#### 运算: + +当使用System.out.println();时 + +System.out.println('""+a+b);不计算 + +System.out.println(a+b);计算 + +System.out.println(a+""+b);不计算。 注:用单引号可能会当字符编码来计算。 + + + + + + + +## 运算符作业 + +```java +// pritse 运算符作业 +package homework; + +import java.util.Scanner; + +public class practise { + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + System.out.println("请输入一个字符:"); + char a = sc.next().charAt(0); + if (a<='9' && a>'0'){ + System.out.println("是数字字符"); + }else { + System.out.println("非数字字符"); + } + + + System.out.println("请输入一个字符:"); + char b =sc.next().charAt(0); + if ((b>='a' && b<='z' )||(b>='A' && b<='Z')){ + System.out.println("是字符"); + }else { + System.out.println("非字符"); + } + + System.out.println("请输入查询的年份:"); + int c =sc.nextInt(); + if (c%4==0 && c%100!=0 && c%400!=0) { + System.out.println("是闰年"); + }else{ + System.out.println("非闰年"); + } + System.out.println("请输入一个三位数:"); + int d =sc.nextInt(); + int e =d%10; + int f =d/10%10; + int g =d/100; + if (e*e*e+f*f*f+g*g*g==d){ + System.out.println("是水仙花数。"); + }else { + System.out.println("不是水仙花数。"); + } + System.out.println("请输入一个五位数:"); + int h =sc.nextInt(); + int i=h%10 ; + int j=h/10000 ; + int k=h/10%10 ; + int l=h/1000%10 ; + System.out.println(i); + System.out.println(j); + System.out.println(k); + System.out.println(l); + if (i==j && k==l){ + System.out.println("是回文数。"); + }else{ + System.out.println("不是回文数"); + } + } +} + + + + + +//practise 练习1 +package homework; + +public class practise2 { + public static void main(String[] args) { + + // 第一题。 + float fatherHeight=177 ; + float mortherHeight=165 ; + + double sonHeight =(fatherHeight+mortherHeight)*1.08/2 ; + double dautherHeight=(fatherHeight*0.923+mortherHeight)/2 ; + System.out.println("儿子身高:"+sonHeight); + System.out.println("女儿身高:"+dautherHeight); + // 第二题 + int readtea =21*2+3; + int greentea =24*2; + + if (readtea==greentea){ + System.out.println("对"); + }else { + System.out.println("不对"); + } + // 第三题 + int price1 =24 ; + int price2 =8 ; + int price3 =3 ; + int price4 =16 ; + System.out.println(price1+" "+price2); + if ((price1+price2+price3)>30) { + if ((price1+price2+price3)*0.830) { + if ((price1+price2+price3)*0.8常量2 ?b (true):c(false) + +为真输出b,假输出c + +### 运算符++ + +int a =0 ; + +a=a++; + +a=a 存入栈1 + +a++(自增)存入栈2;sout(a)得 0; + +#### 情况二 + +int a =0 ; + +int j = a++; + +a=a++; + +sout(a); 得1 + +sout(j);得0 + + 这时a只有一个值,所以我猜取自增值 + +### 逻辑运算符 + +&&:有一个false 则结束判断 + +||: 有一个TRUE则结束判断 + +&:固执的判断以及运行完所有条件 + +|:同上 + +## > >> >>> + +### 大于号 符号右移 无符号右移 + +符号右移:指在二进制的情况下在末尾删去所移动的位数 + +<< 符号左移:指在二进制的情况下在末尾增加所移动的位数 + +每移动一位相当于在十进制中乘2 如4在二进制中为100 则移动两位相当于乘了两次2 + +4>>2 <=> 100>>2 <=> 1(二进制)<=>1 + +4<<2 <=> 100<<2<=>1*10的四次方<=>16 + +16/2=8---0 , + + 8/2=4 ---0 , + + 4/2=2---0, + + 2/2=1---0, + +1/2=---1 + +取余数为10000 + +### 最有效率的2*8 + +为2的左移3 8相当于2的三次方 则左移三位相当于乘了3次2 + +2<<3<=>2*8<=>16<=>10 000 + + + + + +```java +package practise; + +import java.util.Scanner; + +public class practise { + public static void main(String[] args) { + + //第一题 + byte b1 = 10 ; + byte b2 = 20 ; + byte b3 = (byte) (b1+b2) ; + System.out.println("byte类型的b1和b2的和为: " + b3); + + //第二题 + short s1 =1000 ; + short s2 =2000 ; + short s3 = (short)(s1+s2) ; + System.out.println("short类型的s1和s2的和为:" + s3); + + //第三题 + char c1 = 'a' ; + int num = 5 ; + char letter = (char) (c1+num); + System.out.println("char类型的c1和int类型的num的和:" + letter); + + //第四题 + int i1 = 5 ; + int i2 = 2 ; +// int i3 = (byte)(i1 + i2) ; +// System.out.println("i3 = " + i3); + double result=(float) i1/i2 ; + System.out.println("int类型的i1hei2的商是:" + result); + + //第二大题 + int a1=10 ; + int a2=11 ; + System.out.print("10是偶数?"); + System.out.println(a1%2==0); + System.out.print("11是偶数?"); + System.out.println(a2%2==0); + int a3=12 ; + int a4=13 ; + System.out.print("12是奇数?"); + System.out.println(a3%2!=0); + System.out.print("13是奇数?"); + System.out.println(a4%2!=0); + + //第三大题第一小题 + int hours = 89 ; + int day = hours/24 ; + int hour = hours%24 ; + System.out.println('\n'+"为抵抗洪水,战士连续作战: " + day + "天" + hour + "小时"); +// float day2 = (float) hours/24 ; +// System.out.println(day); + + //第四大题 + int today =2 ; + int after= today+(100%7); + if (after!=7) + System.out.println("今天是周" +today + ",100天后是周" + after); + else + System.out.println("今天是周" + today + ",100天后是周" + after); + +// int after2 = (today+103)%7; +// if (after2!= 0) +// System.out.println("今天是周" + today + ",100天后是" + after2); +// else +// System.out.println("今天是周" + today + ",100天后是周日"); + + //第五大题 + Scanner sc = new Scanner(System.in); + System.out.println("请输入x:"); + int x =sc.nextInt() ; + System.out.println("请输入y:"); + int y =sc.nextInt() ; + System.out.println("请输入z:"); + int z =sc.nextInt() ; +// int max1= Math.max(x, y); + int max = x > y ? x : y ; + max = max > z ? max : z ; + System.out.println(x + "," + y + "," + z + "中最大值是:" + max); + + // 第六大题 + System.out.println("请输入年份:"); + int year =sc.nextInt(); + boolean answer = year%4 == 0 && year%100 !=0 ; +// System.out.println(answer); + if (answer==true){ + System.out.println(year + "是闰年"); + }else System.out.println(year + "不是闰年"); + + //第七大题 + System.out.println("请输入要转换成摄氏度的华氏度:"); + double hua = sc.nextDouble(); + double she = (hua-32)/1.8; + System.out.println("华氏度" + hua + "℉" + "转换为摄氏度是" + she + "℃"); + + + + + + + } +} +``` \ No newline at end of file