对象
理解
可以这样来理解,当客户提出需求,比如想要一个电脑功能,你需要根据电脑的功能,去造一些东西,这些东西就是你可以使用的材料,比如变量,常量,静态量你可以根据这些东西去搭好框架也就是方法或者构造器,你可以使用这些东西来解决提出的功能,这就是对象
运用:通过new来创建
循环
理解:就是有规律的重复,
思维: 由繁到简,一步一步简化,找到规律再去优化代码
重点:在企业中一定不能使用嵌套循环,应使用方法,方便调用
四要素
- 初始表达式
- 条件表达式
- 循环体
- 迭代因子
简单的循环 if whlie do{}whlie();
public class MyTest1{
/*主入口*/
public static void main(String[] args){
for(int i=0;i<10;i++){
System.out.println(i+1);
}
int b=0;
while(b<10){
System.out.println(b+1);
b++;
}
int c =0;
do{
System.out.println(c+1);
c++;
}while(c<10);
}
}
由繁到简的推理去做简化
/*System.out.println("helloworld....");
System.out.println("helloworld....");
System.out.println("helloworld....");
*/
/*
//加入计数器
int count = 0;
System.out.println("helloworld....");
count ++;
System.out.println("helloworld....");
count ++;
System.out.println("helloworld....");
count ++;
if(count ==2){
return ;
}
*/
/* //加入了计数器+判断
int count = 0;
if(count<3){
System.out.println("helloworld....");
count ++;
}
if(count<3){
System.out.println("helloworld....");
count ++;
}
if(count<3){
System.out.println("helloworld....");
count ++;
}*/
int count = 0; //初始表达式
while(count<3 /*条件判断*/){
System.out.println("helloworld...."); //循环体
count ++; //迭代因子 改变循环条件
}
System.out.println("----------------");
for(int n=0;n<3;n++){
System.out.println("helloworld....");
}
System.out.println("----------------");
int m =0;
do{
System.out.println("helloworld....");
m++;
}while(m<3);
九九乘法表
当你需要实现某个功能时,你需要使用嵌套循环,就比如九九乘法表,一般初学者都是使用嵌套循环。但在企业,不方便理解,以及以后维护,这里时候你可以把一些规律简化到方法里面后在mian方法里面用一层循环调用另一个循环,这样代码的可维护性就好了很多
企业中推荐使用
package com.liuyi.Dome01;
public class Test02 {
/*主入口*/
public static void main(String[] args) {
for(int i=1;i<10;i++) {
mul(i);
}
}
/*九九乘法表 表里面的*/
public static void mul(int num) {
for(int i=1;i<=num;i++) {
System.out.print(i+"*"+num+"="+i*num+"\t");
}
System.out.print("\n");
}
}