循環嵌套輸出小星星
package lesson02;
public class Demo01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//循環嵌套輸出四行五列小星星
/* * * * * *
* * * * *
* * * * *
* * * * * */
int row=4;//行
int col=5;//列
for(int i=1;i<=row;i++) {//此循環用來控制行數
for(int j=1;j<=col;j++) {//此循環用來控制列數
System.out.print("* ");
}
System.out.println();
}
}
}
循環嵌套輸出直角三角形
package lesson02;
public class Demo02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//循環嵌套輸出直角三角形
/* *
* *
* * *
* * * * */
int row = 4;//行數
for(int i=1;i<=row;i++) {//循環行數
for(int j=1;j<=i;j++) {//控制列數
System.out.print("* ");
}
System.out.println();
}
}
}