コーディングに問題があります。私が形状の高さと幅を入力するように求めるプログラムを作成しようとしています。私はJavaクラスを取っていると考えて、私は初心者です。アスタリスクの2つの平行な形が必要であり、正方形または長方形であることができる。Java Homeworkトラブルアスタリスク
ありがとうございます!
私がこれまでにちょっと
import java.util.Scanner;
public class rectangle {
public static void main(String... args) {
int recHeight = 0;
int recWidth = 0;
Scanner input = new Scanner(System.in);
do {
System.out.print("Enter height [-1 to quit] >> ");
recHeight = input.nextInt();
if (recHeight == -1) {
System.exit(0);
}
/* check if number is valid */
if (recHeight < 2 || recHeight > 24) {
System.err.println("--Error: please enter a valid number");
continue; // prompt again
System.out.print("Enter width [-1 to quit] >> ");
recWidth = input.nextInt();
if (recWidth == -1) {
System.exit(0);
}
/* check if number is valid */
if (recWidth < 2 || recWidth > 24) {
System.err.println("--Error: please enter a valid number");
continue; // prompt again
}
for (int col = 0; col < recHeight; col++) {
for (int row = 0; row < recWidth; row++) {
/* First or last row ? */
if (row == 0 || row == recWidth - 1) {
System.out.print("*");
if (row == recWidth - 1) {
System.out.println(); // border reached start a new line
}
} else { /* Last or first column ? */
if (col == recHeight - 1 || col == 0) {
System.out.print("*");
if (row == recWidth - 1) {
System.out.println();
}
} else {
System.out.print(" ");
if (row == recWidth - 1) {
System.out.println();
}
}
}
}
}
}
} while (true);
}
}
あなたの問題は何ですか?あなたは何を期待していますか、何を得ていますか? –
[回答を受け取るにはどうしたらいいですか?](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – shmosel