Created
November 16, 2016 13:01
-
-
Save mokomokohitsuzi/361a40f0a0b9a1fdeee539cc88f7353e to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-21-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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