【发布时间】:2013-09-24 02:03:20
【问题描述】:
我正在尝试创建一个由用户输入的字符组成的正方形,并由他们选择的尺寸组成。
public class Square
{
public static void main(String[] args)
{
final byte MIN_SIZE = 2,
MAX_SIZE = 20;
byte size;
char fill;
Scanner input = new Scanner(System.in);
do
{
System.out.printf("Enter the size of the square (%d-%d): ",
MIN_SIZE, MAX_SIZE);
size = (byte)input.nextLong();
} while (size > MAX_SIZE || size < MIN_SIZE);
System.out.print("Enter the fill character: ");
fill = input.next().charAt(0);
//This is where the code which outputs the square would be//
}
}
一个正方形应该是什么样子的例子如下: 如果大小为5,填充为“@”
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
【问题讨论】:
-
糟糕的是字符不是正方形的。从技术上讲,你永远不会有正方形。
标签: java loops methods method-chaining