Java インスタンス – 逆三角形を出力する
逆三角形を出力します。
インスタンス
public class InvertedTriangle {
public static void main(String[] args) {
//逆三角形を出力する
for (int m = 1; m <= 4; m++) {
//スペースを出力する
for (int n = 0; n <= m; n++) {
System.out.print(" ");
}
//*を出力する
for (int x = 1; x <= 7 -2 * (m - 1); x++) {
System.out.print("*");
}
System.out.println();
}
}
}
出力結果:
*******
*****
***
*
その他の拡張