我正在尝试创建一个由用户输入的字符制成的正方形,并由他们选择的尺寸制成。
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,填充为“@”
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@