Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created November 9, 2016 14:04
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/60593a6d81d0eea4234a431cedf3f27a to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/60593a6d81d0eea4234a431cedf3f27a to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-16
import java.util.Scanner;
public class En4_16 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n;
do {
System.out.print("何個*を表示ししますか?:");
n = stdIn.nextInt();
if (n <= 0) {
System.out.println("1以上の整数値を入力して下さい。");
}
} while (n <= 0);
for (int i = 1; i <= n; i++) {
// iに1を代入。iがn以下の場合、iをインクリメントしながらループ。
System.out.print('*');
if (i % 5 == 0) {
// iを5で割った時の余りが0の場合(i/5=0の場合)改行
System.out.println();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment