嘿,我真的需要帮助我的 java 编程课程的程序。我将输入到目前为止的说明和代码。任何帮助,将不胜感激!提前致谢!!说明: 编写一个名为 Box (Box.java) 的程序,该程序将使用星号 (*) 打印/显示一个空心盒子形状。程序将读入 2 到 24 范围内的偶数,以指定框中的行数/列数。如果输入的值不正确,则显示错误并重新提示输入数字。然后程序将显示适当大小的空心。提示:在循环中使用循环。基本上它应该是一个方形盒子,所以如果你给它数字 boxSize = 5 输出是一个尺寸为 5x5 的盒子。轮廓由星号组成,但内部是空的
继承人到目前为止我的代码明智
import java.util.Scanner;
public class Box
{
public static void main(String[]args)
{
//numrows and numcols are equal however the spacing is differnt
Scanner input = new Scanner(System.in);
System.out.print("Enter an even number (2-24): ");
int boxSize = input.nextInt();
int numRows = boxSize;
int numCols = numRows;
// This program demonstrates compound decisions with the logical and operator &&
//asks if the number is less than or equal to 24 and greater than or equal to 2 and that the remainder is 0
//when divided by 2, checks if its an even number like it should be
if(boxSize >= 2 && boxSize <= 24 && boxSize%2 == 0)
{
//nested loops are used to print out the asterisk in the correct pattern
for(int r = 0; r<numRows; r++)
{
System.out.println("*");
for(int c = 0; c<numCols; c++)
{
System.out.print("*");
}
}
}
}
//This program demonstrates compound decisions with the logical or ( || ) operator
//checks if any of the following are true
//if one or more is true then that means that it is an incorrect number
//then reprompts the user to put in a new number then checks again
if(boxSize<2||boxSize>24||boxSize% 2 != 0)
{
System.out.println("Value must be an even number from 2-24");
}
基本上我的问题是我不知道在循环中放什么以及在哪里获得形状。如果数字在 2 到 24 之间是否为奇数,我也不知道如何再次使其 REPROMPT 为 boxSize 值,并且它还需要显示错误消息,即值必须在 2 和 24 之间,甚至等等。