/**
for和while的特点:
1,for和while可以互换;
2.格式上的不同,在使用上有点小区别;
如果需要通过变量来对循环进行控制,该变量只作为循环增量存在时,区别就体现出来了。
*/
public class For_Demo5
{
public static void main(String[] args){
/*
int x = 1;
for(x=1;x<=100;x++)
{
if(x%6==0)
{
System.out.println("六的倍数有:"+x);
}
}
*/
/* //打印的一个三角形
for(int x=5;x>=1;x--)
{
for(int y=x;y<=5;y++)
{
System.out.print("*");
}
System.out.println();
}
*/
/*
for(int x=1;x<=5;x++)
{
for(int y=5;y>=x;y--)
{
System.out.print(y);
}
System.out.println();
}
*/
//这是打印的九九乘法表;
for(int x=1;x<=9;x++)
{
for(int y=1;y<=x;y++)
{
System.out.print(y+"*"+x+"="+y*x+"\t");
}
System.out.println("\n");
}
//这是打印的一个等腰三角形,可以给循环标号(取名字)列: abc:for(;;){} 这是为了方便break结束外循环的时候用
for(int x=1;x<=5;x++)
{
for(int y=1;y<x;y++)
{
System.out.print(" ");
}
for(int z=x;z<=5;z++)
{
System.out.print("* ");
}
System.out.println();
}
}
for和while的特点:
1,for和while可以互换;
2.格式上的不同,在使用上有点小区别;
如果需要通过变量来对循环进行控制,该变量只作为循环增量存在时,区别就体现出来了。
*/
public class For_Demo5
{
public static void main(String[] args){
/*
int x = 1;
for(x=1;x<=100;x++)
{
if(x%6==0)
{
System.out.println("六的倍数有:"+x);
}
}
*/
/* //打印的一个三角形
for(int x=5;x>=1;x--)
{
for(int y=x;y<=5;y++)
{
System.out.print("*");
}
System.out.println();
}
*/
/*
for(int x=1;x<=5;x++)
{
for(int y=5;y>=x;y--)
{
System.out.print(y);
}
System.out.println();
}
*/
//这是打印的九九乘法表;
for(int x=1;x<=9;x++)
{
for(int y=1;y<=x;y++)
{
System.out.print(y+"*"+x+"="+y*x+"\t");
}
System.out.println("\n");
}
//这是打印的一个等腰三角形,可以给循环标号(取名字)列: abc:for(;;){} 这是为了方便break结束外循环的时候用
for(int x=1;x<=5;x++)
{
for(int y=1;y<x;y++)
{
System.out.print(" ");
}
for(int z=x;z<=5;z++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
public class While_Demo4
{
public static void main(String[] args){
int x =10;
while(x>=1)
{
System.out.println("x="+x);
x--;
}
do
{
System.out.println("x= "+x);
x++;
}
while (x<=10);
}
}