1,java代码的流程控制: 1, 顺序结构 2, 选择结构 3, 条件结构 4, 循环结构 循环结构的意义
2, 循环结构代码书写:
1,while
2,for
---------------
while循环的两种结构:
while-do
do-while
语法:
逻辑表达式的结果 是否 true 、false
while(逻辑表达式){
}
一直在自己循环的程序 就是死循环
javac a.java -encoding utf8
java Demo
do{
}while()
--------
do-while
while-do的区别:
先do后while
先while后do
============-----------------------------
可以控制循环的次数for
for(int x =0 ; x<3 ;x++ ){
}
for/ if 语句的嵌套; 1,打印一些偶数 for /for 语句的嵌套:
class Demo{
public static void main(String[] args){
/*
逻辑表达式的结果 是否 true 、false
while(逻辑表达式){
}
//代码的注释
int x =33;
while(x>5){
System.out.println("haha");
}
System.out.println("finish");
*/
// 如果x>5 循环继续,, 如果小于5 循环停止
int x =0;
while( x < 100){
x =x+1;
System.out.println(x);
}
System.out.println("finish");
}
}
class Demo{
public static void main(String[] args){
int x =3;
do{
System.out.println("hhaa");
x = x+1;
}while(x<5);
}
}
class Demo{
public static void main(String[] args){
for(int x=0;x<101;x++){
if(x%2 == 0 ){
System.out.println(x);
}
//System.out.println(x+"hehe");
}
}
}
class Demo{
public static void main(String[] args){
/*
***
***
***
------------
*
* *
* * *
---------------
印结果:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
------------
****
***
**
*
****
***
**
*
*
**
****
******
********
-----------
* * * *
* * *
* *
*
*/
//*
//**
//***
//int v =1;
for(int i=1;i<=3;i++){
for(int j=0;j<i;j++){
System.out.print("*");
}
System.out.println();
//v =v+1
}
}
}
class K{
public static void main(String[]agrs){
for(int x=0;x<=9;x++){
for(int y=1;y<=x;y++){
System.out.print(" ");
}
for(int j=1;j<=9-x;j++){
System.out.print("*");
}
System.out.println();
}
}
}