public class circulateMultipleCycle1 {
/*
嵌套循环输出*****
*****
*****
*****
*/
public static void main(String[] args) {
for (int i = 1; i <= 4; i++) {//控制行
for (int j= 1; j <= 5; j++) {//控制列
System.out.print("*");//输出不换行用print
}
System.out.println();//换行
}
}
}
public class circulateMultipleCycle2 {
/*
嵌套循环输出****
***
**
*
*/
public static void main(String[] args) {
for (int i = 1; i <=4; i++) {
for (int j = 4; j >= i; j--) {
System.out.print("*");
}
System.out.println(" ");
}
}
}
public class circulateMultipleCycle3 {
/*
嵌套循环输出*
**
***
****
*/
public static void main(String[] args) {
for (int i = 1; i <=4; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println(" ");
}
}
}
public class circulateMultipleCycle4 {
/*
嵌套循环输出4321
432
43
4
*/
public static void main(String[] args) {
for (int i = 1; i <=4; i++) {
for (int j = 4; j >= i; j--) {
System.out.print(j);//此时j的值就是4321递减的,所以直接输出j就可以
}
System.out.println(" ");
}
}
}
public class circulateMultipleCycle5 {
/*
嵌套循环输出1
22
333
4444
*/
public static void main(String[] args) {
for (int i = 1; i <=4; i++) {
for (int j =1 ; j <=i; j++) {
System.out.print(i);
}
System.out.println();
}
}
}
public class circulateMultipleCycle6 {
/*输出
* * * * *
* * * *
* * *
* *
*
*/
public static void main(String[] args){
for (int i= 1; i<=5; i++){//输出行
for (int j=1; j<i; j++) {
System.out.print(" ");//输出空格
}
for (int k= 1; k<=6-i; k++){//输出*
System.out.print("* ");//这输出的是*和一个空格,这里易错
}
System.out.println();
}
}
}
public class circulateMultipleCycle7MultiplicationTable {//九九乘法表
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + (i * j) + "\t");
}
System.out.println();
}
}
}