[forサイクルの直角三角形]
1938 ワード
public class PrintRightTriangle {
/*
*/
public void print1(){
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++)
System.out.print("*");
System.out.print("
");
}
}
public void print2(){
for(int i=1;i<=9;i++){
for(int j=1;j<=i-1;j++){
System.out.print(" ");
}
for(int k=1;k<=10-i;k++){
System.out.print("*");
}
System.out.print("
");
}
}
public void print3(){
for(int i=1;i<=9;i++){
for(int j=1;j<=9-i;j++)
System.out.print(" ");
for(int k=1;k<=i;k++)
System.out.print("*");
System.out.print("
");
}
}
public void print4(){
for(int i=1;i<=9;i++){
for(int j=1;j<=10-i;j++)
System.out.print("*");
System.out.print("
");
}
}
public static void main(String[] args) {
PrintRightTriangle app = new PrintRightTriangle();
System.out.println("-------------------------");
app.print1();
System.out.println("-------------------------");
app.print2();
System.out.println("-------------------------");
app.print3();
System.out.println("-------------------------");
app.print4();
System.out.println("-------------------------");
}
}