Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created November 16, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/361a40f0a0b9a1fdeee539cc88f7353e to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/361a40f0a0b9a1fdeee539cc88f7353e to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-21-3
import java.util.Scanner;
public class En4_21_3 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n;
do {
System.out.print("右上直角の三角形を表示します。\n段数は:");
n = stdIn.nextInt();
} while (n < 1);
for (int i = n; i > 0; i--) { //段の数を決定
for (int k = 0; k < n-i; k++) {
//kが入力した数(n)-現在の段の数(i)以下の場合に処理
System.out.print(' ');
}
for (int j = i; j> 0; j--) {
System.out.print('*'); //表示
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment