package cn.imust.day01;
public class TestForCircle {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//the general rectangle
/*
******
******
******
******
******
*/
for (int x=0;x<5 ;x++ )//control the external circle
{
for (int y=0;y<5 ;y++ )//control the internal circle
{
System.out.print("*");
}
System.out.println();//just acting as line feed
}
//the triangle like this
/*
*
**
***
****
*****
*/
for (int x=0;x<5 ;x++ )
{
for (int y=0;y<=x ;y++ )
{
System.out.print("*");
}
System.out.println();
}
//the triangle like this
/*
*****
****
***
**
*
*/
for (int x=0;x<5 ;x++ )
{
for (int y=x;y<5 ;y++ )
{
System.out.print("*");
}
System.out.println();
}
/*
1
12
123
1234
12345
*/
for (int x=1;x<6 ;x++ )
{
for (int y=1;y<=x ;y++ )
{
System.out.print(y);
}
System.out.println();
}
}
}
一些for循環嵌套
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.