JAVA撮影練習
🚩 動作を表す
質問する
ユーザーから数値を入力し、次のようにマークします.
ただし、「ㄱ」と「ㄴ」は2以上、「의」は3以上、「의」は5以上を入力する必要があります.
ソースコード
public void practice1() {
Scanner sc = new Scanner(System.in);
System.out.print("숫자 입력 : ");
int num = sc.nextInt();
if (num < 2)
System.out.println("잘못 입력하셨습니다.");
else {
for (int row = 0; row < num; row++) {
for (int col = 0; col < num; col++) {
if (row == 0 || col == num - 1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
sc.close();
}
public void practice2() {
Scanner sc = new Scanner(System.in);
System.out.print("숫자 입력 : ");
int num = sc.nextInt();
if (num < 2)
System.out.println("잘못 입력하셨습니다.");
else {
for (int row = 0; row < num; row++) {
for (int col = 0; col < num; col++) {
if (row == num - 1 || col == 0)
System.out.print("*");
}
System.out.println();
}
}
sc.close();
}
public void practice3() {
Scanner sc = new Scanner(System.in);
System.out.print("숫자 입력 : ");
int num = sc.nextInt();
if (num < 3)
System.out.println("잘못 입력하셨습니다.");
else {
for (int row = 0; row < num; row++) {
for (int col = 0; col < num; col++) {
if (row == 0 || row == num - 1 || col == 0)
System.out.print("*");
}
System.out.println();
}
}
sc.close();
}
public void practice4() {
Scanner sc = new Scanner(System.in);
System.out.print("숫자 입력 : ");
int num = sc.nextInt();
boolean flag = false;
if (num < 5)
System.out.println("잘못 입력하셨습니다.");
else {
for (int row = 0; row < num; row++) {
for (int col = 0; col < num; col++) {
if (row == 0 || row == num - 1 || row == (num - 1) / 2) flag = true;
else if (row <= (num - 1) / 2 && col == num - 1) flag = true;
else if (row > (num - 1) / 2 && col == 0) flag = true;
else flag = false;
if (flag) System.out.print("*");
else System.out.print(" ");
}
System.out.println();
}
}
sc.close();
}
Reference
この問題について(JAVA撮影練習), 我々は、より多くの情報をここで見つけました https://velog.io/@layssingcar/JAVA-별-찍기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol