3.7 Java概述
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
注释:
(文档注释(java独有))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public class HelloJava{
public static void main(String[] args) { System.out.println("Hello World!"); } }
|
javadoc -d mydoc -author -version HelloJava.java
总结
标识符命名
命名规范
类名和文件名命名
类名前面有public 类名和文件名要一样
2.变量
1 2 3 4 5 6 7 8 9
| class variable{ public static void main(String[] args){ int myAge; myAge = 13; System.out.println(myAge); int myNumber = 1001; System.out.println(myNumber); } }
|
3.java定义的数据类型
整型
byte short int long
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class VariableTest3{ public static void main(String[] args){ double d1 = 12.3; int i1 = (int)d1; System.out.println(i1); long l1 = 123; short s2 = (short)l1; System.out.println(s2); int i2 = 128; byte b = (byte)i2; System.out.println(b); } }
|
浮点型
float doule
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class VariableTest4{ public static void main(String[] args){ long l = 123213; System.out.println(l); long l1 = 2141414134324442L; System.out.println(l1); byte b = 12; int b1 = b + 1; System.out.println(b1); } }
|
转义字符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| class VariableTest1{ public static void main(String[] args){
byte b1 = 12; byte b2 = -128; System.out.println(b1); System.out.println(b2); short s1 = 128; int i1 = 1234; long l1 = 41423551531413L; System.out.println(l1); double d1 = 123.3; System.out.println(d1); float d2 = 12.3F; System.out.println(d2); char c1 = 'a'; System.out.println(c1); char c2 = '1'; char c3 = '中'; System.out.println(c2); System.out.println(c3); String a1 = "Hello"; String a2 = "World!"; System.out.println(a1 + '\t' + a2); char c4 = '\u0043'; System.out.println(c4); boolean bb1 = true; System.out.println(bb1); boolean isMarried = true; if(isMarried){ System.out.println("你就不可以参加\"单身party\"了!\n很遗憾"); }else{ System.out.println("你就可以多谈女朋友"); } } }
|
4.自动类型提升运算
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public class VariableTest2{ public static void main(String[] args){ byte b1 = 2; int i1 = 129; int i2 = b1 + i1; System.out.println(i2); float i3 = b1 + i1; System.out.println(i3); short s1 = 123; double d1 = s1; } }
|
5.进制
string运算
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| class VariableTest5{ public static void main(String[] args){ String s1 = "Hello World!"; System.out.println(s1); String s2 = "a"; String s3 = ""; int number = 1001; String numberStr = "学号: "; String info = numberStr + number; String info1 = info + true; System.out.println(info1); char c = 'a'; int num = 10; String str = "hello"; System.out.println(c + num + str); System.out.println(c + str + num); System.out.println(c + (num + str)); System.out.println(str + num + c); System.out.println(num + c + str); } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
javac -encoding UTF-8 .\Imessage.java
**4.扩展学习部分
1 2 3 4 5 6 7 8 9
| class Title{ public static void main(String[] args){ System.out.println("姓名:龙坤long\n"); System.out.println("性别:男"); System.out.println("家庭住址:金华职业技术学院"); } }
|
print打印输出
println打印输出换行
总结
第一天转战java 因为学过两天的c++和一学期的python上手也比较块,昨天花一天装了jdk和环境变量,今天一口气看了50集,二倍数,一些和c++一模一样,理解了基本语法,案例什么自己也可以敲出来,不用看老师。
3.8 java运算
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
算数运算符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
class ReviewTest{ public static void main(String[] args){ int num1 = 12; int num2 = 5; int result2 = num1 / num2; System.out.println(result2); int result3 = num1 / num2 * num2; System.out.println(result3); double result1 = (double)num1 /num2; System.out.println(result1); double result6 = (double)(num1 /num2); System.out.println(result6); double result4 = num1 / (num2 + 0.0); System.out.println(result4); double result5 = (num1 +0.0) /num2; System.out.println(result5); int m1 = 12; int n1 = 5; System.out.println(m1 % n1); int m2 = -12; int n2 = 5; System.out.println(m2 % n2); int m3= 12; int n3 = -5; System.out.println(m3 % n3); int m4 = -12; int n4 = -5; System.out.println(m4 % n4); int a1 =10; int b1 = ++a1; System.out.println("a1 = " + a1 + ",b1 = " + b1); int a2 = 10; int b2 = a2++; System.out.println("a2 = " + a2 + ",b2 = " + b2); short s1 = 10; s1++; System.out.println(s1); type bb1 = 127; bb1++; System.out.println(bb1); } }
|
赋值运算符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
class ReviewTest2{ public static void main(String[] args){ int j1 = 10; int j2 = 10; int i1,i2; i2 = j2 = 10; int i3 = 10,j3 = 10; int m1 = 14; int n1 = 5; m1 %= n1; System.out.println(m1); } }
|
比较运算符
逻辑运算符
三元运算符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public class SanYuanTest{ public static void main(String[] args){ int m = 5; int n = 12; int max = (m>n)?m:n; System.out.println(max); n = 12; String maxStr = (m>n)?"m大":((m == n)? "m和n相等":"n大"); System.out.println(maxStr); int a = 15,b = 8,c = 3; String maxSan = (a>b)? ((a>c)? "a大":"c大"): ((b>c)?"b大":"c大"); System.out.println(maxSan); } }
|
键盘获取(if语句)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import java.util.Scanner; class ReviewTest4{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("姓名:"); String name = input.next(); System.out.println("学号:"); long studentNumber = input.nextLong(); System.out.println("成绩:"); int success = input.nextInt(); String s; if(success>=90){ System.out.println(name+studentNumber+":"+"A"); }else if(success>=80){ System.out.println(name+studentNumber+":"+"B"); }else if(success>=70){ System.out.println(name+studentNumber+":"+"C"); }else if(success>=60){ System.out.println(name+studentNumber+":"+"D"); }else{ System.out.println(name+studentNumber+":"+"E"); } } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
**4.扩展学习部分
总结
java运算符和python里不太一样,& 和| 分不太清,后面找资料明白了,自己创作了博客关于&和| 区分。其他加减乘除都理解了,类型之间有的通过运算会转换不太理解。明天再看。
3.10 switch 语句
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
switch的case语句可以处理int,short,byte,String,char类型的值,但是不能处理long,等类型。
1 2 3 4 5 6 7 8 9 10
| switch(表达式){ case 表达式常量1:语句1; break; case 表达式常量2:语句2; break; ...... case 表达式常量n:语句n; break; [default:语句n+1;] }
|
case语句后面要加break 不然会继续向下直接执行下一个条件 不管满不满足
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class SwitchDemo { public static void main(String[] args) { int month = 8; String monthString; switch (month) { case 1: monthString = "January"; break; case 2: monthString = "February"; break; case 3: monthString = "March"; break; case 4: monthString = "April"; break; case 5: monthString = "May"; break; case 6: monthString = "June"; break; case 7: monthString = "July"; break; case 8: monthString = "August"; break; case 9: monthString = "September"; break; case 10: monthString = "October"; break; case 11: monthString = "November"; break; case 12: monthString = "December"; break; default: monthString = "Invalid month"; break; } System.out.println(monthString); } }
|
JDK1.8以后支持String
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class TestSwitch01{ public static void main (String[] args){ String A = "perfect"; switch(A) { case "perfect": System.out.println("完美"); break; default: System.out.println("不完美"); } } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
default的位置不同运行结果不同:
java里switch的执行顺序
switch表达式的值决定选择哪个case分支,如果找不到相应的分支,就直接从”default” 开始输出。
当程序执行一条case语句后,因为例子中的case分支中没有break 和return语句,所以程序会执行紧接于其后的语句。
**4.扩展学习部分
判断闰年 月份日期 是这年的第几天
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| import java.util.Scanner; class code2{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("请输入年份"); int year = input.nextInt(); System.out.println("请输入月份"); int month = input.nextInt(); System.out.println("请输入日期"); int day = input.nextInt(); int sumDay = 0; if((year % 4 ==0||year % 100 != 0)&&(year % 400 == 0)){ for(int r=1;r<month;r++){ switch (r){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: sumDay += 31; break; case 4: case 6: case 9: case 11: sumDay += 30; break; case 2: sumDay += 29; break; } } System.out.println("是闰年" + (day+sumDay));
} else{ for(int i=1;i<month;i++){ switch (i){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: sumDay += 31; break; case 4: case 6: case 9: case 11: sumDay += 30; break; case 2: sumDay += 28; break; } } System.out.println("不是闰年" + (day+sumDay));
} } }
|
总结
switch语句在java和c++一模一样基本学过了,和if方法应该是互通的,default的位置对代码的影响可能是没接触过的,今天学习时间不太多,只学了switch和if这两块内容,一天就十几集。
3.11 循环
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
For循环
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| package day04;
public class ForTest { public static void main(String[] args) { for(int i = 0; i < 5;i++) { System.out.println("Hello World!"); } int num = 1; for (System.out.println('a');num<=3; System.out.println('c'),num++){ System.out.println('b'); }int count = 0;
for(int a = 0;a<=100;a++){ if(a%2==0){ System.out.println(a); count += 1;}
} System.out.println(count); } }
|
While循环
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| package day04;
public class WhileTest { public static void main(String[] args) { int i =0; while (i<=100){ if (i%2 == 0) System.out.println(i); i++; }
} }
|
Do while 循环
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package day04;
public class DoWhileTest { public static void main(String[] args) { int i = 0; do { if(i % 2 == 0){ System.out.println(i); } i++; }while (i<=100); } }
|
无限循环
for(;;)
while(true)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package day04;
import java.util.Scanner; public class Test01 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int count1 = 0; int count2 = 0; while(true) { int a = input.nextInt(); if(a > 0) count1 ++; else if (a < 0) count2 ++; else break; } System.out.println("正数"+count1+"个"); System.out.println("负数"+count2+"个"); } }
|
循环嵌套
外循环代表行数
内循环代表列数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| package day04;
public class ForForTest { public static void main(String[] args) { for(int i = 1;i<=5;i++){ for (int a = 1;a<=i;a++){ System.out.print("="); } System.out.println(); } } }
|
九九乘法表
1 2 3 4 5 6 7 8 9 10 11 12
| package day04;
public class ForForTest1 { public static void main(String[] args) { for(int i = 1;i<=9;i++){ for(int j = 1;j<=i;j++){ System.out.print(j + " * " + i + " = "+(i*j)+" "); } System.out.println(); } } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
IDEA总是中文乱码
所有编码改成gbk
**4.扩展学习部分
水仙花数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| package day04;
public class ShuiXian { public static void main(String[] args) { for(int i = 100;i<1000;i++){ int a = i % 10; int b = i / 10 % 10; int c = i / 100; if(i == Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)){ System.out.println(i); } } } }
|
最大公约数最小公倍数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| package day04; import java.util.Scanner;
public class ForTest1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入两个数字:"); int m = input.nextInt(); int n = input.nextInt(); int z = 0; for(int y = Math.min(m,n);y>0;y--){ if(n % y ==0 && m % y== 0){ z += y; break; } } System.out.println("最大公约数是:"+z); int s = m*n/z; System.out.println("最小公倍数是:"+s); } }
|
打印图案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| package day04;
public class ForForTest { public static void main(String[] args) { for(int i = 1;i<=5;i++){ for (int b = 1;b<=5-i;b++){ System.out.print(" "); } for (int a = 1;a<=i;a++){ System.out.print("* "); } System.out.println(); } for(int c = 1; c<=4;c++){ for (int d = 1; d<=c;d++){ System.out.print(" "); } for (int e = 1;e <=5-c;e++){ System.out.print("* "); } System.out.println(); } } }
|
判断质数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| package day04;
public class ForForTest2 { public static void main(String[] args) { int z = 0; boolean a = true; long start = System.currentTimeMillis(); for(int i = 2;i<100;i++){ for(int j = i/2;j>1;j--){ if(i % j == 0) { a = false; break; } } if(a){ System.out.println(i+"是质数"); z++;} a = true; } System.out.println("质数一共有"+z); long end = System.currentTimeMillis(); System.out.println(end - start); } }
|
总结
今天主要是学习了三个循环,用法呢基本和python一样,语法稍微有点不同,初始化条件,循环条件----boolean类型,循环体,迭代条件的放置位置不太一样,今天主要是敲代码,因为已经掌握知识,敲代码也是游刃有余,将之前python的一些循环判断题都用java的方法做一下。
3.14收支记账软件
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
收支软件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| package day04;
import java.util.Scanner; public class FamilyAccount { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String details = ("收支 账户金额 收入金额 说 明"+"\n"); boolean islend = true; int balance = 0; while (islend) { System.out.println("-------------------家庭收支记账软件--------------------"); System.out.println(); System.out.println(" 1 收支登记"); System.out.println(" 2 登记收入"); System.out.println(" 3 登记支出"); System.out.println(" 4 退出"); System.out.println(); System.out.print(" 请选择<1-4>:"); int input = sc.nextInt(); switch (input){ case 1: System.out.println("-------------------当前收支记录明细--------------------"); System.out.println(details); System.out.println("------------------------------------------------------"); System.out.println(); break; case 2: System.out.println("(输入0返回菜单)"); System.out.print("本次收入金额:"); int income = sc.nextInt(); if (income > 0) { balance += income; System.out.print("本次收入说明:"); String info = sc.next(); details += ("收入\t\t"+balance+"\t\t\t"+income+"\t\t "+info+"\n"); System.out.println(".登记完成."); } break; case 3: System.out.println("(输入0返回菜单)"); System.out.print("本次支出金额:"); int money = sc.nextInt(); if (money<=balance && money!=0) { balance -= money; System.out.print("本次支出说明:"); String spending = sc.next(); details += ("支出\t\t"+balance+"\t\t\t"+money+"\t\t "+spending+"\n"); System.out.println(".登记完成."); break; } else if(money > balance && money != 0){ System.out.println("你没有这么多钱,花不了,去赚钱"); break; } else { break; } case 4: while (true) { System.out.println("是否确认退出 Y/N:"); String a = sc.next(); char exit = a.charAt(0); if (exit == 'Y' || exit == 'y') { System.out.println("退出成功!"); islend = false; break; } else if (exit == 'N' || exit == 'n') { break; } else { System.out.println("输入错误请重新输入"); } } } }
} }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
退出系统时,需要输入Y/N,python里就是直接判断就好,于是按照字符串,判断,发现不行,不可比较的类型: java.lang.String和char提示,想到可以输入一个char,用atchar方法,翻阅了笔记,就解决了。
**4.扩展学习部分
看了大致安装Eclipse的样子,选择自己用IDEA。
总结
今天主要就是敲了这个案例,早上复习了一下上周的continue标签,收支案例和python的名片系统差不多,先看第一节课老师对这个小软件的使用方法,就自己基本打出来了,在老师的方法之上稍微完善了一下,人性化了一下,等学了数组可以完善,加入修改的作用。然后因为自己用的IDEA 关于EClipse都跳掉了。
3.15数组
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
数组
静态数组和动态数组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class Array01 { public static void main(String[] args) { int[] ids = new int[]{1001, 1002, 1003, 1004};
String[] names = new String[5]; names[0] = "张三"; names[1] = "李四"; names[2] = "王五"; names[3] = "小明"; names[4] = "小美"; System.out.println(ids.length); System.out.println(ids[1]); System.out.println(names.length); String z = names[1]; System.out.println(z); for (String name : names) { System.out.println(name); } } }
|
如上
静态数组在创建的时候,数据就已经定义好了
动态数组只是定义长度,数据可以后续添加
数据添加 调用 遍历
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package day05;
public class Array02 { public static void main(String[] args) { int [] nums = new int[900]; for(int i = 0; i<900;i++){ int num = (i+100); nums[i] = num; } for (int name:nums){ int num4 = 0; for (int j =0; j<3;j++){ char nums1 = (""+name).charAt(j); int y = Character.getNumericValue(nums1); num4 += Math.pow(y,3); } if (num4 == name){ System.out.println(name); } } } }
|
For-Each 循环
https://www.runoob.com/java/java-array.html
JDK 1.5 引进了一种新的循环类型,被称为 For-Each 循环或者加强型循环,它能在不使用下标的情况下遍历数组。
语法格式如下:
1 2 3 4
| for(type element: array) { System.out.println(element); }
|
二维数组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| package day05; import java.lang.String; public class ArrayTest2 { public static void main(String[] args) { int[][] arr = new int[4][3]; System.out.println(arr[0][0]); arr[1] = new int[]{1,2,3}; arr[2] = new int[4]; System.out.println(arr[1][2]); arr[2][1] = 30; System.out.println(arr[2][1]); String[] StrS = new String[5]; StrS[2] = "Tom"; StrS = new String[3]; System.out.println(StrS[3]); } }
|
语法
1 2 3
| int[][] arr = new int[][]
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
搞了半天是取数组数据的方法错了 应该是
**4.扩展学习部分
IDEA会自动给你修复最佳方案,在char变字符串,在和字符串合并的时候
知道了一个StringBuilder方案,CSDN找了用法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| package day05; import java.util.Scanner; public class Subject { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入要统计的字符: "); String count = input.nextLine(); int count1 = 0; StringBuilder str1 = new StringBuilder(); int count2 = 0; int count3 = 0; StringBuilder str2 = new StringBuilder(); int count4 = 0; StringBuilder str3 = new StringBuilder(); for (int i = 0; i<count.length();i++){ char Character = count.charAt(i); if (((int) Character >=65 && (int) Character <= 90)||((int) Character >=97 && (int) Character <= 121)) { count1 ++; str1.append(Character); } else if ((int) Character == 32) count2 ++;
else if ((int) Character >= 48 && (int) Character <= 57) { count3 ++; str2.append(Character); } else { count4 ++; str3.append(Character); } } System.out.println("存在字母个数:" + count1); System.out.println("存在字母如下:" + str1); System.out.println(); System.out.println("存在数字个数:" + count3); System.out.println("存在数字如下:" + str2); System.out.println(); System.out.println("存在空格个数:" + count2); System.out.println(); System.out.println("存在其他个数:" + count4); System.out.println("存在其他如下:" + str3); } }
|
总结
二维数组中,引用类型没有理解透彻今天的学习状态还是满意的。学了数组很多,存储数据的题目都可以做了,在java的题目中做了7道题,跟老师也敲了几个案例。但是一些用法不确定java中有没有,自动添加数据这种,不然数组【int】 = “”
这种方法,有点麻烦,看懂用法就去做了题目,但是感觉自己的方法很长,应该有更简单的,需要寻找一下。
3.18数组扩展算法
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
今天多是打代码题目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day06;
public class ArrayExer2 { public static void main(String[] args) { int[][] arr = new int[10][];
for (int x = 0; x < arr.length;x++) { arr[x] = new int[x + 1]; arr[x][0] = arr[x][x] =1;
for (int y = 1;y<x;y++){ arr[x][y] = arr[x-1][y-1]+arr[x-1][y]; }
} for (int[] num : arr) { for (int name : num) { System.out.print(name + " "); } System.out.println(); } } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| package day06;
public class Test3 { public static void main(String[] args) { int[] arr = new int[10]; for (int i = 0; i < arr.length; i++) { boolean count = true; int value = (int) (Math.random() * 90 + 10); for (int j = 0; j <= i; j++) { if (value == arr[j]) { count = false; i--; break; } } if (count) arr[i] = value; int MaxValue = 0; int MinValue = arr[0]; int Sum = 0; for (int num : arr) { System.out.print(num + " "); if (MaxValue < num) { MaxValue = num; } if (MinValue > num) { MinValue = num; } Sum += num; } System.out.println(); System.out.println("最大值:" + MaxValue); System.out.println("最小值:" + MinValue); System.out.println("总和:" + Sum); double Cc = (double) Sum / 10; System.out.println("平均数:" + Cc); } } }
|
导入随机数不重复
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public class ArrayExer3 { public static void main(String[] args) { int[] arr = new int[6]; for (int i = 0;i<arr.length;i++){ boolean count = true; int value = (int)(Math.random()*29 + 1); for (int j = 0;j<=i;j++) { if (value == arr[j]) { count = false; i--; break; } } if (count){ arr[i] = value; }
} for (int name : arr){ System.out.println(name); } } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
暂无
**4.扩展学习部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| package day06;
public class Test4 { public static void main(String[] args) { int[] arr1, arr2; arr1 = new int[]{2, 3, 5, 7, 11, 13, 17, 19}; System.out.print("arr1: "); for (int num : arr1) { System.out.print(num + " "); } arr2 = arr1; System.out.println(); System.out.print("arr2: "); for (int i = 0; i < arr2.length; i++) { if (i % 2 == 0) { arr2[i] = i; } System.out.print(arr2[i] + " "); } System.out.println(); System.out.print("arr1: "); for (int num : arr1) { System.out.print(num + " "); } } }
|
arr1 arr2复制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package day06;
public class Test5 { public static void main(String[] args) { int[] arr1,arr2; arr1 = new int[]{2,3,5,7,11,13,17,19}; System.out.print("arr1: "); for (int num : arr1){ System.out.print(num+" "); } arr2 = new int[arr1.length]; for (int j = 0;j<arr1.length;j++){ arr2[j] = arr1[j]; } System.out.println(); System.out.print("arr2: "); for (int i =0; i<arr2.length;i++){ if (i % 2 == 0){ arr2[i] = i; } System.out.print(arr2[i]+" "); } System.out.println(); System.out.print("arr1: "); for (int num : arr1){ System.out.print(num+" "); } } }
|
总结
今天只有一下午的学习时间,刚好学习到算法,算法比其他内容还是稍微难点,题目自己做也做的出来,但是要状态好,犯困的话是做不出来的,今天学习状态一般般,下午有点困,下午做了很多题目,老师出的题目,自己做得出来,基本掌握了,有空看下算法书。
3.21 数组应用
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
数组的反转
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| package day07;
public class ArrayTest01 { public static void main(String[] args) { String[] arr = new String[]{"JJ", "DD", "CC", "XX", "YY"}; String[] arr1 = new String[arr.length]; System.arraycopy(arr, 0, arr1, 0, arr.length); for (String arr01 : arr1) { System.out.print(arr01 + " "); } System.out.println(); System.out.print("方法一:"); for (int j = 0; j < arr.length / 2; j++) { String temp = arr[j]; arr[j] = arr[arr.length - j - 1]; arr[arr.length - j - 1] = temp; } for (String arr02 : arr) { System.out.print(arr02 + " "); } System.out.println(); System.out.print("方法二:"); for (int i = 0, j = arr.length - 1; i < j; i++, j--) { String temp2 = arr[i]; arr[i] = arr[j]; arr[j] = temp2; } for (String arr02 : arr) { System.out.print(arr02 + " "); } } }
|
数组的查找
线性查找
可以查找String int 等类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import java.util.Scanner; public class ArrayTest02 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[] arr = new String[]{"JJ", "DD", "CC", "XX", "YY"}; System.out.print("请输入你要查找的字符: "); String test = input.nextLine(); boolean count = true; for (int a = 0;a< arr.length;a++){ if (test.equals(arr[a])){ System.out.print("找到了指定元素的位置"); System.out.println(a); count = false; break; } } if (count){ System.out.println("很遗憾,没找到"); }
|
二分法查找
只能查找int数组 而且要是拍好顺序的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| int [] arr1 = new int[]{-89,-6,1,6,7,23,44,77,80,82}; System.out.print("请输入你要查找的数字: "); int test1 = input.nextInt(); int start = 0; int end = arr1.length-1; while (start <= end){
int middle = (start + end)/2; if (test1 == arr1[middle]){ System.out.println("找到了指定元素,位置:"+"[" + middle + "]"); break; } else if (arr1[middle] > test1){ end = middle -1; } else { start = middle + 1; } }
|
排序
冒泡排序(难理解)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public class ArrayTest03 { public static void main(String[] args) { int [] arr = new int[]{-5,-9,5,1,9,7,6,5,3,4}; for (int i = 0;i<arr.length-1;i++){
for (int j = 0;j < arr.length - 1 -i;j++){ if (arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } for (int num : arr){ System.out.print(num+" "); } } }
|
Array方法
直接使用
代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package day07;
import java.util.Arrays;
public class ArrayClass { public static void main(String[] args) {
int [] arr1= new int[]{1,2,5,6}; int [] arr2= new int[]{1,8,2,6,-5}; boolean isEquals = Arrays.equals(arr1,arr2); System.out.println(isEquals);
System.out.println(Arrays.toString(arr1));
Arrays.fill(arr1,10); System.out.println(Arrays.toString(arr1));
Arrays.sort(arr2); System.out.println(Arrays.toString(arr2));
int [] arr3 = new int[]{-97,24,-56,-4,2,25,46,23,9,82,11,19}; Arrays.sort(arr3); int index = Arrays.binarySearch(arr3,46); System.out.println(index); } }
|
数组常见异常
1,数组脚边越界异常 ArrayIndexOutOfBoundsException
2,空指针异常 NullPointerException
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package day07;
public class ArrayExceptionTest { public static void main(String[] args) {
} }
|
数组总结
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| package day07;
import java.util.Arrays; import java.util.Scanner;
public class Test { public static void main(String[] args) { int [] list = new int[]{34,5,22,-98,-3,-76,0}; for (int i = 0 ;i<list.length-1;i++){ for (int j =0; j < list.length-i-1;j++){ if (list[j]>list[j+1]){ int temp = list[j]; list[j] = list[j+1]; list[j+1] = temp; } } } System.out.println(Arrays.toString(list)); for (int x = 0;x<list.length/2;x++){ int temp1 = list[x]; list[x] = list[list.length-1-x]; list[list.length-1-x] = temp1; } System.out.println(Arrays.toString(list)); int[] list1 = new int[list.length]; for (int y = 0;y < list.length;y++){ list1[y] = list[y]; } System.out.println(Arrays.toString(list1)); Scanner input = new Scanner(System.in); System.out.print("输入要查找的数字:"); int sc = input.nextInt(); int z = 0; for (;z < list.length;z++){ if (sc == list[z]){ System.out.println("找到了位置是在"+"["+z+"]"); break; } } if (z == list.length){ System.out.println("不好意思没找到"); } } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
binarySearch方法中 数组里有的数据,查找 返回值竟然是负数
binarySearch方法是二分查找法,所以要先排序,才能查找,不然就会有问题
**4.扩展学习部分
题目:求s=a+aa+aaa+aaaa+aa…a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。输出结果的形式如:2+22+222=246;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day07;
import java.util.Scanner;
public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入要想加的数字:"); int num = input.nextInt(); System.out.print("请输入要相加的数字的个数:"); int count = input.nextInt(); int cumulative = 0; int z = 0; for (int i = 0; i < count;i++){ cumulative = cumulative*10 + num; z += cumulative;
} System.out.print("输出: "); System.out.print(z); } }
|
总结
今天学习时间只有一上午,主要复习了上星期的学习内容,将面向对象之前的内容巩固了一下,找了一些题目做,学习状态不错也完成了自己定的目标,题目也都 做出来了。
3.22 面向对象
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
1.面向对象学习的主线
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| package day08;
public class ClassTest { public static void main(String[] args) { Person p1 = new Person();
p1.names = "小明"; p1.isMale = true; System.out.println(p1.names); p1.eat(p1.names); p1.play(p1.names); p1.ages(p1.names, p1.age); p1.talk("中国话");
System.out.println("p2 **********************************"); Person p2 = new Person(); System.out.println(p2.names); System.out.println(p2.age); System.out.println(); System.out.println("p3 **********************************"); Person p3 = p1; System.out.println(p3.names); p3.age = 21; System.out.println(p1.age);
} } class Person{ int age = 18; String names; boolean isMale;
public void eat(String name){ System.out.println(name + "要吃饭"); } public void play(String name){ System.out.println(name+"喜欢玩游戏"); } public void ages(String name,int age){ System.out.println(name + "今年" + age + "岁"); } public void talk(String language){ System.out.println("全世界都在说"+language); } }
|
2.对象的内存解析
分为栈和堆
栈是类中的属性
堆是方法中的局部变量
3.局部变量和属性的异同
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package day08;
public class UserTest { public static void main(String[] args) { User p1 = new User(); System.out.println(p1.name); System.out.println(p1.age); System.out.println(p1.isMale); p1.talk("中文"); p1.eat(); } }
class User{ String name; public int age; boolean isMale;
public void talk(String language){ System.out.println("我们使用" + language + "说话"); } public void eat(){ String food = "烙饼"; System.out.println("北方人喜欢吃"+ food); } }
|
4.方法的声明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| package day08;
import java.util.Arrays;
public class CustomerTest { public static void main(String[] args) { Customer p1 = new Customer(); p1.name = "Tom"; p1.age = 19; p1.eat(); p1.sleep(5); System.out.println(p1.getName()); System.out.println(p1.getNation("中国")); int[] arr = new int[]{1,5,9,-6,-2,4,2}; p1.sort(arr); System.out.println(Arrays.toString(arr)); } }
class Customer{
String name; int age;
public void eat(){ System.out.println("吃饭咯"); } public void sleep(int hour){ System.out.println("我睡了" + hour +"个小时"); eat();
} public String getName(){ if (age>18){ return name; } else { return "小学生"; } } public String getNation(String nation){ return "我的国籍是" + nation; } public void sort(int[] arr){ for (int i = 0;i<arr.length-1;i++){ for (int j = 0;j < arr.length - 1 -i;j++){ if (arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
无
**4.扩展学习部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| package day08;
public class Test3 { public static void main(String[] args) { Test3 test = new Test3(); test.method1(); System.out.println("------------------------------"); System.out.println(test.method2()); System.out.println("------------------------------"); System.out.println(test.method3(10,8)); }
public void method1(){ for (int i =0; i < 10;i++){ for (int j=0; j < 8;j++){ System.out.print("* "); } System.out.println(); } }
public int method2(){ for (int i =0; i < 10;i++){ for (int j=0; j < 8;j++){ System.out.print("* "); } System.out.println(); } return 10*8; }
public int method3(int length,int width){
for (int i =0; i < length;i++){ for (int j=0; j < width;j++){ System.out.print("* "); } System.out.println(); } return (length) * (width); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| package day08;
public class ClassTest4 { public static void main(String[] args) { Student[] stu = new Student[15]; ClassTest4 test = new ClassTest4(); test.create(stu); test.print(stu); System.out.println("*******************************"); test.screening(stu); System.out.println("*******************************"); test.sort(stu); test.print(stu); } public void create(Student[] stu){ for (int i = 0; i < stu.length;i++){ stu[i] = new Student(); stu[i].number = i+1; stu[i].state = (int)(Math.random()*6 +1); stu[i].score = (int)(Math.random()*100 +1); } }
public void print(Student[] stu){ for (int j = 0; j < stu.length;j++){ System.out.println(stu[j].tables()); } } public void screening(Student[] stu){ for (Student student : stu) { if (student.state == 3) { System.out.println(student.tables()); }
} } public void sort(Student[] stu){ for (int i = 0;i < stu.length-1;i++){ for (int j = 0; j < stu.length -i-1;j++){ if (stu[j].score > stu[j+1].score){ Student temp = stu[j]; stu[j] = stu[j+1]; stu[j+1] = temp; } } } } } class Student{ int number; int state; int score; public String tables(){ return "学号:" + number + " 年级:" + state + "成绩:" + score; } }
|
总结
今天学习很满意的,写了两个略微长点的案例,80行左右,接触了面向对象,和python中的差不多,学起来也是蛮容易的,java的方法和python的函数作用差不多,上手很快,二倍数看完,回头去敲案例,很顺利,今天也是彻底把昨天的冒泡排序弄懂了,对快速排序有兴趣,等学到递归去敲,学习目标。学习状态也是不错。
3.25方法的重载
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
认识重载
重载就是两同一不同 同一个类 同一个方法名 参数列表不同
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| package day10;
public class OverLoadExer { public static void main(String[] args) { OverLoadExer test = new OverLoadExer(); test.mOL(5); test.mOL(5,8); test.mOL("Hello World"); } public void mOL(int i){ System.out.println(i * i); } public void mOL(int i , int j){ System.out.println(i * j); } public void mOL(String i){ System.out.println(i); } }
|
jdk5.0 新内容 …可变个数形参
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package day10;
public class MethodArgsTest { public static void main(String[] args) { MethodArgsTest test = new MethodArgsTest(); test.show(12); test.show("hello","world"); System.out.println(); test.show("ggg"); } public void show(int i){ System.out.println("show(int)");
} public void show(String i){ System.out.println("Show(String)"); } public void show(String ... str){ System.out.println("Show(String...str)"); for (String CC : str){ System.out.print(CC+"/"); } } }
|
值传递机制
1.错误的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| package day10;
public class ValueTransferTest1 { public static void main(String[] args) { int m = 10; int n = 20; System.out.println("m = " + m + " n = " + n);
ValueTransferTest1 test1 = new ValueTransferTest1(); test1.swap(m,n);
System.out.println("m = " + m + " n = " + n);
} public void swap(int m,int n){ int temp = m; m = n; n = temp; } }
|
2.正确的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day10;
public class ValueTransferTest2 { public static void main(String[] args) { Date date = new Date(); date.m = 10; date.n = 20; System.out.println("m = " + date.m + " n = " + date.n);
int temp = date.m; date.m = date.n; date.n = temp; System.out.println("m = " + date.m + " n = " + date.n); ValueTransferTest2 test2 = new ValueTransferTest2(); test2.swap(date); System.out.println("m = " + date.m + " n = " + date.n); } public void swap(Date d){ int temp = d.m; d.m = d.n; d.n = temp; } } class Date{ int m; int n; }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
暂无
**4.扩展学习部分
内容结构
总结
今天的内容很难理解,先是对JVM内存的内存结构和对象内存解析,然后是数组的内存解析,内存解析不太容易理解,堆和栈的关系等等,能够帮助理解的代码也是敲了7 8遍,在后面学习了重载,理解了重载和使用等,比较容易掌握的,学习状态也是不错。下午比较精神,静下心来去学习了。
3.28递归 && 封装性
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
递归练习
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package day11;
public class RecursionTest { public static void main(String[] args) { int sum = 0; for(int i =1;i<=100;i++){ sum += i; } System.out.println(sum);
RecursionTest test = new RecursionTest(); System.out.println(test.getSum(100)); System.out.println(test.f(10)); System.out.println(test.fibonacci(10)); } public int getSum(int num){ if (num == 1){ return 1; } return num + getSum(num-1); } public int f(int num){ if (num == 0){ return 1; } else if (num == 1){ return 4; } return f(num-2) + (2*f(num-1)); } public int fibonacci(int num){ if (num == 1 || num ==2){ return 1; } return fibonacci(num-1)+fibonacci(num-2); } }
|
封装和隐藏
private关键字
私有的
方法赋值 可设置条件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package day11;
public class AnimalTest { public static void main(String[] args) { Animal animal = new Animal(); animal.name = "大黄"; animal.age = 5; animal.setLegs(4); System.out.println(animal.getLegs()); animal.show(); animal.eat(); }
}
class Animal{ String name; int age; private int legs; public void setLegs(int l){ if (l > 0 && l % 2 == 0){ legs = l; } else { legs = 0; } } public int getLegs(){ return legs; } public void eat(){ System.out.println("吃东西"); } public void show(){ System.out.println("name = " + name + " age = " + age + " legs = " + legs); }
}
|
问题的引入
封装性的体现
极限修饰符来配合
测试代码在day11中
构造器
构造器和python中的____init____ 差不多初始化话方法
传递参数 初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| package day11.java4;
public class PersonTest { public static void main(String[] args) { Person p = new Person(); p.eat(); Person p1 = new Person("Tom",18); p1.show(); }
}
class Person{ String name; int age; public Person(){ System.out.println("Person()....."); } public Person(String n,int a){ name = n; age = a;
} public void eat(){ System.out.println("人吃饭"); } public void show(){ System.out.println("name = " + name + " age = " + age); } }
|
属性赋值的过程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| package day11.java4;
public class UserTest { public static void main(String[] args) { User user = new User(); System.out.println(user.age); User user1 = new User(2); user1.setAge(4); System.out.println(user1.age);
} }
class User{ String name; int age = 1; public User(){
} public User(int a){ age = a; } public void setAge(int a){ age = a; } }
|
this的使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| package day11.java4;
public class customerTest { public static void main(String[] args) { System.out.println("方式一"); customer cc = new customer(184564,"CC"); cc.show();
System.out.println("方式二"); customer dd = new customer(); dd.setId(1545); dd.setName("DD"); dd.show(); } } class customer { private int id; private String name;
public customer() {
}
public customer(int id, String name) { this.id = id; this.name = name; }
public void setId(int id) { this.id = id; }
public int getId() { return id; }
public void setName(String name) { this.name = name; }
public String getName() { return name; } public void show(){ System.out.println("name = " + this.getName() + " id = " + this.getId()); } }
|
this修饰调用构造器
3、遇到的问题描述(可以附上截图)+解决⽅案**
递归返回值 num+2 方法里没有num+2的值 是死循环
解决方案: 检查代码
报错说是没有java.lang.String
去CSDN看format保留小数的用法,发现后面那个类型要是数字类型的,才能保留
修改
**4.扩展学习部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| package day11.java4;
public class Test { public static void main(String[] args) { Test w = new Test(); for (int i=-100;i<100000;i++){ if (w.wan(i+100) && w.wan(i+168)){ System.out.println(i); } } } public boolean wan(int num){ for (int j = 1;j<num;j++){ if (j*j == num){ return true; } } return false; } }
|
总结
今天上午学习很精神,也很有学习劲头。学习内容前面的传递机制不是很好理解,在方法内部的值传递有点不太容易,按照自己想当然容易冗余。后面的重载和构造器以及递归,因为和python的面向对象差不多,所以理解起来很容易。拉进度条,找到题目,直接做,在看老师的代码,概念的不好理解就多看几遍\
3.29 this package import
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
this关键字的使用
this调用构造器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| package day12;
public class customerTest { public static void main(String[] args) { System.out.println("方式一"); customer cc = new customer(184564,"CC"); cc.show();
System.out.println("方式二"); customer dd = new customer(); dd.setId(1545); dd.setName("DD"); dd.show(); System.out.println(); System.out.println("方式三"); customer CC = new customer(18,"CC"); System.out.println(CC.getId());
} } class customer { private int id; private String name;
public customer() { this.eat(); } public customer(int id) { this(); this.id = id; } public customer(String name) { this(); this.name = name; } public customer(int id, String name) { this(name); this.id = id;
}
public void setId(int id) { this.id = id; }
public int getId() { return id; }
public void setName(String name) { this.name = name; }
public String getName() { return name; } public void show(){ System.out.println("name = " + this.getName() + " id = " + this.getId()); } public void eat(){ System.out.println("人要吃饭"); } }
|
this练习
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day12;
public class Boy { private String name; private int age; public Boy(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } public void marry(Girl girl){ System.out.println("我想娶" + girl.getName()); } public void shout(){ if (this.age >= 22){ System.out.println("你可以合法结婚了"); } else { System.out.println("多谈谈恋爱"); } } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day12;
public class Girl { private String name; private int age;
public Girl(String name, int age) { this.name = name; this.age = age; }
public String getName() { return name; }
public int getAge() { return age; } public void marry(Boy boy){ System.out.println("我想嫁给" + boy.getName()); boy.marry(this); } public int compare(Girl girl){ return this.getAge() - girl.getAge(); } }
|
main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package day12;
public class BoyGirlTest { public static void main(String[] args) { Boy boy = new Boy("罗密欧",22); boy.shout(); Girl girl = new Girl("朱丽叶",16); girl.marry(boy); Girl girl1 = new Girl("祝英台",17); int compare = girl.compare(girl1); if (compare < 0){ System.out.println(girl.getName() + "大" +Math.abs(compare)+"岁"); }else if (compare > 0){ System.out.println(girl1.getName() + "大" +Math.abs(compare)+"岁"); }else { System.out.println(girl.getName()+"和"+girl1.getName()+"一样大"); } } }
|
输出
综合练习1
account类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| package day12.Test;
public class Account { private int id; private double balance; private double annualInterestRate;
public Account(int id, double balance, double annualInterestRate) { this.id = id; this.balance = balance; this.annualInterestRate = annualInterestRate; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public double getBalance() { return balance; }
public void setBalance(double balance) { this.balance = balance; }
public double getAnnualInterestRate() { return annualInterestRate; }
public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; }
public void withdraw(double amount){ if (amount > balance){ System.out.println("余额不足,无法取出"); } else { balance -= amount; System.out.println("成功取出:" + amount); } } public void deposit(double amount){ if (amount > 0){ balance += amount; System.out.println("成功存入" + amount); }else { System.out.println("请输入正确的数字"); } } }
|
custom类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package day12.Test;
import day12.Test.Account;
public class Customer { private final String firstName; private final String lastName; private Account account;
public Customer(String f, String l) { this.firstName = f; this.lastName = l; }
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
public Account getAccount() { return account; }
public void setAccount(Account account) { this.account = account; } }
|
main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| package day12.Test;
public class customerTest { public static void main(String[] args) { Customer customer = new Customer("Jane","Smith"); Account account = new Account(10086,2000,0.0123); customer.setAccount(account); customer.getAccount().deposit(100); customer.getAccount().withdraw(960); customer.getAccount().withdraw(2000); System.out.println("名字:" + customer.getLastName()+"," + customer.getFirstName()+" 账户: " + customer.getAccount().getId()+" 余额: " + customer.getAccount().getBalance() + " 年利率: " + customer.getAccount().getAnnualInterestRate()); } }
|
输出
综合练习2
account1类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package day12.Test2;
public class Account1 { private double balance; public Account1(double init_balance){ this.balance = init_balance; } public double getBalance(){ return balance; } public void withdraw(double amount){ if (amount > balance){ System.out.println("余额不足,无法取出"); } else { balance -= amount; System.out.println("成功取出:" + amount); } } public void deposit(double amount){ if (amount > 0){ balance += amount; System.out.println("成功存入" + amount); }else { System.out.println("请输入正确的数字"); } } }
|
custom1类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day12.Test2; public class Customer1 { private final String firstName; private final String lastName; private Account1 account;
public Customer1(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }
public Account1 getAccount1() { return account; }
public void setAccount(Account1 account) { this.account = account; }
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; } }
|
bank类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package day12.Test2;
public class Bank { private final Customer1[] customers; private int numberOfCustomer;
public Bank(int count){ customers = new Customer1[count]; } public void addCustomer(String f,String l){ Customer1 customer = new Customer1(f,l); customers[numberOfCustomer] = customer; numberOfCustomer ++; } public Customer1 getCustomers(int index) { if (index >= 0 && index < numberOfCustomer){ return customers[index]; } return null; } public String getNumberOfCustomer() { return "已经添加顾客" + numberOfCustomer + "人"; }
}
|
测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| package day12.Test2;
public class bankTest { public static void main(String[] args) { Bank bank = new Bank(10); bank.addCustomer("小明","王"); bank.getCustomers(0).setAccount(new Account1(2000)); bank.getCustomers(0).getAccount1().deposit(100); bank.getCustomers(0).getAccount1().withdraw(500); bank.getCustomers(0).getAccount1().withdraw(2500);
System.out.println("名字:" + bank.getCustomers(0).getLastName() +" "+ bank.getCustomers(0).getFirstName()+" 余额: " + bank.getCustomers(0).getAccount1().getBalance()); bank.addCustomer("Jane","Smith"); System.out.println(bank.getNumberOfCustomer()); } }
|
输出
import package包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| package day12; import day12.Test2.Account; import day12.Test2.Bank; import java.util.*;
public class packageImportTest { public static void main(String[] args) { String info = Arrays.toString(new int[]{1,2,3,4}); Bank bank = new Bank(10); ArrayList list = new ArrayList(); HashMap map = new HashMap(); Scanner s = null; System.out.println("Hello!"); Account acct = new Account(10); day12.Test5.Account acct1 = new day12.Test5.Account(1000,2000,0.0123); } }
|
MVC了解
3、遇到的问题描述(可以附上截图)+解决⽅案**
空指针异常,报错在14行,说没有定义数组,但是在构造器中,我已经定义了数组,看了一遍老师的代码,发现我多了Custom1[ ] 加了一个这个意思是创造一个新的数组,只是数组名字一样,把Custom1去掉就正常了。
正常截图
**4.扩展学习部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| package day12;
public class subject11 { public static void main(String[] args) { for (int i = 1; i <= 4;i++){ for (int j =1;j <= 4;j++){ for (int k = 1;k <= 4;k++){ if (i!=j && j != k && k != i){ System.out.println("1,2,3,4可以组成的三位数:"+i+j+k); } } } } } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package day12;
import java.util.Scanner;
public class subject15 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入你要输入几个数:"); int i = input.nextInt(); int[] arr = new int[i]; for (int j = 0;j<i;j++){ arr[j] = input.nextInt(); } for (int a =0;a<arr.length-1;a++) { for (int b = 0;b <arr.length-1-a;b++){ if (arr[b] > arr[b+1]){ int temp = arr[b]; arr[b] = arr[b+1]; arr[b+1] = temp; } } } for (int num : arr){ System.out.println(num); } } }
|
递归经典题目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| package day12;
public class subject20 { public static void main(String[] args) {
double sumNum = sum(20); System.out.println("前20规律数之和为:"+sumNum); } public static double sum(int num){ if (num == 1){ return 2.0; } else { double a = getMolecule(num); double b = getMolecule(num-1); return sum(num-1)+ a/b; } } public static double getMolecule(int num){ if(num == 2){ return 3.0; }else if (num == 1){ return 2.0; }else { return getMolecule(num-1) + getMolecule(num-2); } } }
|
总结
今天的学习时间充足看了20多集,4个小时,其他时间基本都在敲练习,今天写了三个练习,银行存钱的,前面一个this调用比较简单容易理解,后面的一个数组的,可以加入多个对象的,有点难,死磕了一个小时,视频看了两三遍才弄明白,理解它的意思结构,在写数组那个练习的时候,因为自己并列的两个包名一样,调用的时候,搞混了,一直在检查,改名还改错,顺利解决以后,刚好来到了老师讲包和import,也直接明白了自己为什么错,以后应该怎么办,不是改个名这么容易。今天学习劲头也有,很满意。
3.31项目二
1.头:日期、所学内容出处
黑马程序员Python教程_600集Python从入门到精通教程(懂中文就能学会)_哔哩哔哩_bilibili
2.今天所学内容摘要**
项目二
代码主类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| package day13.java1;
public class CustomerView {
private final CustomerList customerList = new CustomerList(10);
public CustomerView(){
}
public void enterMainMenu(){ boolean loopFlag = true;
while (loopFlag) { System.out.println("\n------------------客户信息管理软件------------------"); System.out.println(" 1.添 加 客 户"); System.out.println(" 2.修 改 客 户"); System.out.println(" 3.删 除 客 户"); System.out.println(" 4.客 户 列 表"); System.out.println(" 5.退 出\n"); System.out.print(" 请选择(1-5):");
char menu = CMUtility.readMEnuSelection(); switch (menu) { case '1': System.out.println("添加客户的操作");
addNewCustomer(); break; case '2': System.out.println("修改客户的操作");
modifyCustomer(); break;
case '3': System.out.println("删除客户的操作");
deleteCustomer(); break;
case '4':
System.out.println("--------------------客户列表-----------------"); listAllCustomer(); break;
case '5': System.out.println("确认是否退出(Y/N)"); char isExit = CMUtility.readConfirmSelection(); if (isExit == 'Y' || isExit == 'y'){ loopFlag = false; } else if (isExit == 'n' || isExit == 'N'){ break;} } } } private void addNewCustomer(){ System.out.println("--------------------添加客户-----------------"); System.out.print("姓名: "); String name = CMUtility.readString(10);
System.out.print("性别: "); char gender = CMUtility.readChar();
System.out.print("年龄: "); int age = CMUtility.readInt();
System.out.print("电话: "); String phone = CMUtility.readString(13); System.out.print("邮箱: "); String email = CMUtility.readString(30);
Customer customer = new Customer(name,gender,age,phone,email); boolean aa =customerList.addCustomer(customer); if (aa){ System.out.println("------------------添加成功------------------"); } else { System.out.println("------------------添加失败------------------"); } } private void modifyCustomer(){
System.out.println("------------------修改客户------------------"); int number; Customer custs; while (true){ System.out.print("请选择待修改客户的编号(-1退出): "); number = CMUtility.readInt(); if (number == -1){ return; } custs = customerList.getCustomer(number-1); if (custs == null){ System.out.println("未找到指定客户!"); }else { break; } } System.out.print("姓名(" + custs.getName()+"):"); String name = CMUtility.readString(10,custs.getName()); System.out.print("性别(" + custs.getGender()+"):"); char gender = CMUtility.readChar(custs.getGender());
System.out.print("年龄(" + custs.getAge()+"):"); int age = CMUtility.readInt(custs.getAge());
System.out.print("电话(" + custs.getPhone()+"):"); String Phone = CMUtility.readString(13,custs.getPhone());
System.out.print("邮箱(" + custs.getEmail()+"):"); String email = CMUtility.readString(30,custs.getEmail());
Customer newCust = new Customer(name,gender,age,Phone,email); boolean isReplace =customerList.replaceCustomer(number - 1,newCust); if (isReplace){ System.out.println("------------------修改成功------------------"); }else { System.out.println("------------------修改失败------------------");
}
} private void deleteCustomer(){ System.out.println("------------------删除客户------------------"); int number; while (true) { System.out.print("请选择待修改客户的编号(-1退出): "); number = CMUtility.readInt(); if (number == -1){ return; } if (number <=0 || number > customerList.getTotal()){ System.out.println("无法找到指定客户!"); }else { break; } } System.out.print("确认是否删除(Y/N)"); char isDelete = CMUtility.readConfirmSelection(); if (isDelete == 'Y' || isDelete == 'y'){ boolean deleteSuccess = customerList.deleteCustomer(number-1); if (deleteSuccess){ System.out.println("------------------删除成功------------------"); } else { System.out.println("------------------删除失败------------------"); } } } private void listAllCustomer(){ int total = customerList.getTotal(); if (total == 0){ System.out.println("------------------没有客户记录------------------"); } else{ System.out.println("编号\t姓名\t 性别\t\t年龄\t\t电话\t\t\t 邮箱"); Customer[] custs = customerList.getAllCustomer(); for (int i = 0;i < custs.length ; i++){ Customer customer = custs[i]; System.out.println(((i+1) + "\t\t" + customer.getName() + "\t\t" + customer.getGender() + "\t\t" + customer.getAge()+ "\t\t" + customer.getPhone() + "\t\t" + customer.getEmail())); } } System.out.println("------------------客户列表完成------------------");
}
public static void main(String[] args) { CustomerView customerView = new CustomerView(); customerView.enterMainMenu(); } }
|
对象数组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| package day13.java1;
public class CustomerList { private final Customer[] customers ; private int total = 0;
public CustomerList(int totalCustomer){ customers = new Customer[totalCustomer]; } public boolean addCustomer(Customer customer){ if (total >= customers.length){ return false; } customers[total++] = customer; return true; } public boolean replaceCustomer(int index,Customer cust){ if (index<0 || index >= total){ return false; } customers[index] = cust; return true; } public boolean deleteCustomer(int index){ if (index<0 || index >= total){ return false; } for (int i= index;i<total-1;i++){ customers[i] = customers[i+1]; } customers[--total] = null; return true; } public Customer[] getAllCustomer(){ Customer[] custs = new Customer[total]; System.arraycopy(customers, 0, custs, 0, total); return custs; } public Customer getCustomer(int index){ if (index<0 || index >= total){ return null; } return customers[index]; } public int getTotal(){ return total; }
}
|
用户信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| package day13.java1;
public class Customer { private String name; private char gender; private int age; private String phone; private String email;
public void setName(String name) { this.name = name; }
public void setGender(char gender) { this.gender = gender; }
public void setAge(int age) { this.age = age; }
public void setPhone(String phone) { this.phone = phone; }
public void setEmail(String email) { this.email = email; } public Customer(){
} public Customer(String name,char gender,int age,String phone,String email){ this.name = name; this.age = age; this.email = email; this.gender = gender; this.phone = phone; }
public String getName() { return name; }
public char getGender() { return gender; }
public int getAge() { return age; }
public String getPhone() { return phone; }
public String getEmail() { return email; } }
|
工具包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| package day13.java1;
import java.util.Scanner;
public class CMUtility { private static final Scanner input = new Scanner(System.in); public static char readMEnuSelection() { char a; while (true){ String arr = readKeyBoard(1,false); a = arr.charAt(0); if (a != '1' && a != '2' && a != '3' && a != '4' && a != '5') { System.out.print("选择错误请重新输入 : "); } else break; } return a; } public static char readChar() { String str = readKeyBoard(1,false); return str.charAt(0);
} public static char readChar(char defaultValue){ String str = readKeyBoard(1,true); return (str.length()==0)?defaultValue : str.charAt(0); } public static int readInt(){ int n; while (true){ String str = readKeyBoard(2,false); try { n = Integer.parseInt(str); break; }catch (NumberFormatException e){ System.out.println("数字输入错误,请重新输入"); } } return n; } public static int readInt(int defaultValue){ int n; while (true){ String str = readKeyBoard(2,true); if (str.equals("")){ return defaultValue; } try { n = Integer.parseInt(str); break; }catch (NumberFormatException e){ System.out.println("数字输入错误,请重新输入"); } } return n; } public static String readString(int limit){ return readKeyBoard(limit,false); }
public static String readString(int limit,String defaultValue){ String str = readKeyBoard(limit,true); return str.equals("")? defaultValue :str; }
public static char readConfirmSelection() { char a; while (true){ String arr = readKeyBoard(1,false).toUpperCase(); a = arr.charAt(0); if (a != 'N' && a != 'Y' && a != 'n' && a != 'y' ) { System.out.print("选择错误请重新输入(Y/N) : "); } else break; } return a; } public static String readKeyBoard(int limit,boolean blankReturn){ String line = ""; while (input.hasNextLine()){ line = input.nextLine(); if (line.length() ==0){ if (blankReturn) return line; else continue; } if (line.length() > limit){ System.out.println("输出长度(不大于" + limit + ")错误,请重新输入"); } break; } return line;
} }
|
继承
理解继承代码
Creature ------- person---------Student
1 2 3 4 5 6 7
| package day13.java2;
public class Creature { public void breath(){ System.out.println("gggggggg"); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package day13.java2;
public class Person extends Creature { String name; private int age; public Person(){
}
public Person(String name, int age) { this.name = name; this.age = age; } public void eat(){ System.out.println("要吃饭"); } public void sleep(){ System.out.println("要睡觉"); }
public void setAge(int age) { this.age = age; } public int getAge(){ return age; } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package day13.java2;
public class Student extends Person{ String major;
public Student() {
}
public Student(String name, int age, String major) { this.name = name; this.setAge(age); this.major = major; }
public void study(){ System.out.println("要学习"); } }
|
测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package day13.java2;
public class ExtendsTest { public static void main(String[] args) { Person p1 = new Person(); p1.setAge(28); p1.name = "汪大东"; p1.eat();
Student student = new Student(); student.setAge(18); System.out.println(student.getAge()); student.name = "金宝三"; student.major = "电工"; student.eat(); student.study();
student.breath(); Creature creature = new Creature();
} }
|
继承圆和圆柱
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| package day13.java4;
public class Circle { private double radius; public Circle(){ this.radius = 1.0; }
public double getRadius() { return radius; }
public void setRadius(double radius) { this.radius = radius; } public double findArea(){ return Math.PI * radius*radius; } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package day13.java4;
public class Cylinder extends Circle{ private double length;
public Cylinder() { this.length =1.0; }
public double getLength() { return length; }
public void setLength(double length) { this.length = length; } public double findVolume(){ return findArea()*length; }
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| package day13.java4;
public class CylinderTest { public static void main(String[] args) { Cylinder cylinder = new Cylinder(); cylinder.setRadius(2.1); cylinder.setLength(3.4); double volume = cylinder.findVolume(); System.out.println("半径是:" + cylinder.getRadius()); System.out.println("圆柱的体积是:" + String.format("%.2f",volume)); double area = cylinder.findArea(); System.out.println("圆柱的底面积是:" + String.format("%.2f",area)); } }
|
3、遇到的问题描述(可以附上截图)+解决⽅案**
不输入的时候,回车,会报错。检查自己的工具包发现用的是next、,改成nextLine就好了
**4.扩展学习部分
面试高频题
重载和重写的区别
总结
项目二总体来说,是这个阶段比较难的了,用了目前学到的实用的方法都用到了,经过这个项目,对对象数组理解也更加透彻了,难点在于工具包,输入比较难,一些没使用过的package和方法,要去搜索一下,用法,写完还是很有成就感的,写完再看看代码是如何运行的,今天学习有劲头,写完项目二把继承都搞明白了。