【发布时间】:2014-09-11 13:04:27
【问题描述】:
我需要帮助制作一个程序,让您在控制台中指定箭头的尺寸。
import java.util.Scanner;
public class Project6 {
public static void main(String[] args) {
int height = 0;
int width = 0;
boolean run = true;
Scanner scanner = new Scanner(System.in);
int rows = 0;
while (run) {
System.out.println("Please Specify The Demensions of Your Arrow:");
System.out.print("\tHeight: ");
if (!(scanner.hasNextInt())) {
System.out.println("Please Enter an Integer.");
} else {
height = scanner.nextInt();
if (!(height > 0)) {
if (height == -1) {
break;
} else {
System.out.println("Please Enter A Positive Integer");
}
} else {
System.out.print("\tWidth: ");
if (!(scanner.hasNextInt())) {
System.out.println("Please Enter An Integer");
} else {
width = scanner.nextInt();
if (!(width > 0)) {
if (width == -1) {
break;
} else {
System.out.println("Please Enter A Positive Integer");
}
}
}
}
if (width % 2 == 0) {
System.out.println("Width is an Even Number");
} else {
System.out.println("Width is odd");
for (int numRow = width; numRow >= 1; numRow -= 2) {
System.out.println(numRow);
rows++;
}
System.out.println("Number of Rows: " + rows);
}
/*if(height % 2 == 0) {
System.out.println("height is an Even Number");
} else {
System.out.println("height is odd");
for(int numCol = height; numCol >= 1; numCol -=2) {
System.out.println(numCol);
}
}*/
}
}
}
}
我在 cmets 中加入了一部分,因为我不确定我是否想保留它。这是我所能得到的。我不知道从这里去哪里。基本上我想做的是,例如:你输入height: 10和width: 9,它看起来像这样:
*
***
*****
*******
*********
***
***
***
***
***
【问题讨论】: