Created
November 9, 2016 14:04
-
-
Save mokomokohitsuzi/60593a6d81d0eea4234a431cedf3f27a to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-16
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_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