尚学堂Java学习日记Day8
第8天老师回顾了以往的教学内容,做了知识总结整理。
1.例:double box = 99; //double = int
2.例:int x = (int)3.14;
1.例:
有规律的重复 不变+可变 ->多次选择
题: 打印5次HelloWorld…
System.out.println(“HelloWorld”);
System.out.println(“HelloWorld”);
System.out.println(“HelloWorld”);
System.out.println(“HelloWorld”);
System.out.println(“HelloWorld”);
//计数
int count = 0;
if(count < 5){
System.out.println(“HelloWorld”);
count =1;
}
if(count < 5){
System.out.println(“HelloWorld”);
count =2;
}
if(count < 5){
System.out.println(“HelloWorld”);
count =3;
}
if(count < 5){
System.out.println(“HelloWorld”);
count =4;
}
if(count < 5){
System.out.println(“HelloWorld”);
count =5;
}
if(count < 5){
System.out.println(“HelloWorld”);
count++;
}
//使用循环
int count = 0;
while(count < 5){
System.out.println(“HelloWorld”);
count++;
}
例:1、单选择
if(){
}
2、双选择
if(){
}else{
}
3、多选择
if(){
}else if(){
}else if(){
}else{}
例:switch(定值判断|字符串){
case 值1:
case 值2:
case 值3:
defaut:
}
4.for用于能够确定循环次数
5.while用于不能确定循环次数
例:随机生成 0-100的整数,遇到88停止
1.public int add(int a,int b){
return a+b;
}
public void test(){
}
方法的位置: 类中 方法外 ,独立于其他方法 ,不能嵌套|包含
2.确保唯一性
1.public class 类型{
属性
构造块
构造器
方法
}
2.类 引用|对象名 = new 类型();
类 引用|对象名 = new 构造器;
1、开辟空间 -->内存分析
2、初始化
3、返回地址给引用 匿名对象
存: 对象名.属性= 值;
取: 对象名.属性
4.调用: 接收变量 = 对象名.方法名(实参列表)
5.1、名称与类同名
2、没有返回类型
3、不能随便调用 new
6.1、没有参数的构造器
public Xxx(){
//方法体… 初始化信息的
}
2、没有编写构造器 ,javac编译加入无参构造 确保一个至少存在一个构造器
老师要求我们每天都有总结下今天所学,每周都要总结画出之前所学的思维导图。