Blogger background: a certain non-university college, a junior college major in accounting, currently self-taught, reading videos while reading books, slowly understanding the logical relationship of the code, then summarizing, outputting notes, have you studied together in a team, if the article is correct If you are helpful, please like, follow and collect. One-click three consecutive 666 walks. Keep's high-quality output is responsible for yourself, and it also makes every novice take less detours, thank you.
public class homework02 {
public static void main(String[] args) {
for (int i = 10; i > 0; i--) {
System.out.println("i = " + i);
}
System.out.println("-------------分割线---------------");
for (int i = 10; i > 0; i -= 2) {
System.out.println("i = " + i);
}
System.out.println("-------------分割线---------------");
for (int i = 100; i >= 10; i /= 3) {
System.out.println("i = " + i);
}
}
}
Code idea:
i=10, i>0, the output result i=10, the program execution ends, i=i–=9; i=9, i>0, the output result i=9, the program execution ends, i=i–= 8; i=8, i>0, the output result i=8, the program execution ends, i=i–=7; and so on.
for loop nesting
public class homework04 {
public static void main(String[] args){
//循环5次
for(int i = 1;i <= 5; i++){
System.out.print("i = " + i + ",");
}
System.out.println();
//循环2次
for(int j=1;j<=2;j++){
System.out.print("j="+j+",");
}
System.out.println();
//把i循环放在j循环体当中,先内部循环5次,在外部循环2次
for(int j = 1;j <= 2;j++){
for(int i = 1;i <= 5;i++){
System.out.print("i="+i+",");
}
}
}