【黑马最新JavaSE零基础入门到入土(idea版)】 https://www.bilibili.com/video/BV1Yb411z7PG/?p=24&share_source=copy_web&vd_source=43433c569f3f927c6cbd442b49ffb849
P24 数据类型转换 注意事项(第二天 10.25)
P25 ASCLL编码表
48 - ‘0’
65 - ‘A’
97 - ‘a’
P26算术运算符
取余 %
注意事项:一旦运算当中有不同数据类型,结果将是数据范围类型大的那种
P28 自增自减运算符 (第三天 10.26)
P35 方法的调用
P36 jshell小工具
P37 编译器的两点优化
P45 穿透switch 语句
default 里的 break 不建议省略
P46 循环结构
第一句do 无条件执行
while后面的 ; 很容易丢
P50 练习_用循环求出1-100之间的偶数和 (第四天 10.27)
//用循环求出1-100之间的偶数和
//思路
//1. 从1-100一个一个进行检查
//2. 必须是偶数才可以,判断(if)偶数:num % 2 == 0
//3. 需要一个变量进行存储 和 sum
for循环
public class Sum{
public static void main(String[] args){
int sum = 0;
for(int num = 1; num <= 100; num++){
if (num % 2 == 0){
sum += num;
}
}
System.out.println(sum); //2550
}
}
while 循环
public class Sum{
public static void main(String[] args){
int sum = 0;
int num = 1;
while (num <= 100 ){
if(num % 2 ==0) {
sum += num;
}
num++;
}
System.out.println(sum); //2550
}
}
do - while 循环
public class Sum{
public static void main(String[] args){
int sum = 0;
int num = 1;
do{
if(num % 2 == 0) {
sum += num;
}
num++;
}while (num <= 100);
System.out.println(sum); //2550
}
}
P52 循环控制_break _continue语句(第五天 10.28)
P54 死循环
P55 循环嵌套
//时分秒
public class HourAndMinute {
public static void main(String[] args){
for(int hour = 1; hour < 24; hour++){
for(int minute = 1; minute < 60; minute++){
for(int second = 1; second < 60; second++){
System.out.println(hour + "时" + minute + "分" + second + "秒");
}
}
}
}
}
P61 IDEA常用快捷键
idea同时选中多个相同的内容并编辑和替换
Ctrl + F
Ctrl + R
P65 方法的三种调用(第六天 10.29)
此前学习的方法,返回值类型固定为void,这种方法只能单独调用,不能打印调用或者赋值调用
调用流程图
P67 对比有参数和无参数
P68 对比有返回值和无返回值
P69 方法练习
1、比较两个数字是否相同
//定义一个方法,用来判断两个数字是否相同
public class NumSame {
public static void main(String[] args) {
System.out.println(isSame(10,20));//false
System.out.println(isSame(20,20));//true
}
/*
* 三要素
* 返回值类型:boolean
* 方法名称:isSame
* 参数列表:int a, int b*/
public static boolean isSame(int a, int b) {
/*boolean same;
if (a == b) {
same = true;
} else {
same = false;
}
return same;*/
/*boolean same = a == b?true:false;
return same;*/
return a==b;
}
}
2、求出1-100的累加和
//1-100求和
public class Sum1_100 {
public static void main(String[] args) {
System.out.println("结果是" + isSum());
}
/*三要素
* 返回值类型:int
* 方法名称:isSum
* 参数列表:数据范围已经固定 无参*/
public static int isSum() {
int sum = 0;
for (int i = 1; i <= 100; i++) {
sum += i;
}
return sum;
}
}
P73 方法重载
方法名称一样,参数列表不一样
P75 重载方法练习
//比较两个数据是否相等
//参数类型分别为两个byte类型,两个short类型,两个int类型,两个long类型
public class OverLoad {
public static void main(String[] args) {
byte a = 1;
byte b = 2;
System.out.println(same(a, b));
System.out.println(same((short) 1, (short) 1));
System.out.println(same(1, 2));
System.out.println(same(11L, 11L));
}
public static boolean same(byte a, byte b) {
System.out.println("两个byte参数方法执行");
boolean same;
if (a == b) {
same = true;
} else {
same = false;
}
return same;
}
public static boolean same(short a, short b) {
System.out.println("两个short参数方法执行");
return a == b ? true : false;
}
public static boolean same(int a, int b) {
System.out.println("两个int参数方法执行");
return a == b;
}
public static boolean same(long a, long b) {
System.out.println("两个long参数方法执行");
if (a == b) {
return true;
} else {
return false;
}
}
}
P80 数组
P84内存划分
一个数组的内存图
两个数组的内存图
两个引用指向同一个数组的内存图
P89 常见问题 空指针异常
P90 获取数组长度
P92 练习 求数组中的最值
package practice;
import java.util.Arrays;
public class ArrayMax {
public static void main(String[] args) {
int[] arr = {1, -2, 22, 122, 33, 28, 100, 2000, -88, -3};
//调用toString打印数组
System.out.println(Arrays.toString(arr));
//求数组arr 的最大值和最小值
int max = arr[0];
int min = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr[i] >= max) {
max = arr[i];
}
if (arr[i] <= min) {
min = arr[i];
}
}
System.out.println("最大值为:" + max);
System.out.println("最小值为:" + min);
}
}
P93 练习 数组元素反转
package practice;
public class ArrayReverse {
public static void main(String[] args) {
int[] array = {1,2,3,4,5};
//遍历数组本来的样子
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
System.out.println("----------------");
//表示对称位置需要两个索引
for (int min = 0, max = array.length-1; min < max ; min++, max--) {
int temp = array[min];
array[min] = array[max];
array[max] = temp;
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
P94数组作为方法参数_传递地址
P95数组作为方法返回值_返回地址
P101 对象的创建以及使用(第七天 10.30)
P102 一个对象的内存图
黑色 × 代表执行完方法立即出栈
栈:先进后出
P103 两个对象使用同一个方法的内存图
P104 两个引用指向同一个对象的内存图
P105 使用对象类型作为方法的参数
P106 使用对象类型作为方法的返回值
P107 成员变量和局部变量的区别
P109 private关键字的作用及使用
P110
P111
P119 匿名对象的说明
使用建议:如果确定有一个对象只需要使用唯一的一次,就可以用匿名对象。|