java:如何确认数组已在数组操作菜单中创建
所以我正在制作这个数组操作菜单,我的第一个选项是“创建一个数组”。我应该在这里输入数组的大小,但如果它小于5或>20,它将发送一条错误消息,我可以这样做。但是如果已经创建了数组,我还应该显示一条错误消息。我该怎么做?谢谢你的回复java:如何确认数组已在数组操作菜单中创建,java,arrays,menu,bluej,Java,Arrays,Menu,Bluej,所以我正在制作这个数组操作菜单,我的第一个选项是“创建一个数组”。我应该在这里输入数组的大小,但如果它小于5或>20,它将发送一条错误消息,我可以这样做。但是如果已经创建了数组,我还应该显示一条错误消息。我该怎么做?谢谢你的回复 class process{ Scanner in = new Scanner(System.in); int choice1 =0; int limit1; int array[]; public void m(){ Sy
class process{
Scanner in = new Scanner(System.in);
int choice1 =0;
int limit1;
int array[];
public void m(){
System.out.println(" ARRAY OPERATION");
System.out.println(" menu");
System.out.println(" [1] Create Array");
System.out.println(" [2] Insert Element");
System.out.println(" [3] Search");
System.out.println(" [4] Display");
System.out.println(" [5] Delete");
System.out.println(" [0] Stop");
System.out.print(" Enter choice:");
e();
}
public void e(){
choice1 = in.nextInt();
cls();
switch(choice1){
case 1:
{
System.out.println("Create Array");
System.out.println("Enter the limit of your array: ");
limit1 = in.nextInt();
if(limit1 <5){
System.out.println("Error: Minimum limit exceeded");
System.out.println("Going back to main menu");
m(); //loop to main menu
}
else if(limit1 >20){
System.out.println("Error: Maximum limit exceeded");
System.out.println("Going back to main menu");
m(); //loop to main menu
}
else if(limit1 >=5 || limit1 <=20){
System.out.println("An array with a limit of " + limit1 + " has been created");
array = new int[limit1];
m();
}
}
类进程{
扫描仪输入=新扫描仪(系统输入);
int-choice1=0;
int limit1;
int数组[];
公屋{
System.out.println(“数组操作”);
System.out.println(“菜单”);
System.out.println(“[1]创建数组”);
System.out.println(“[2]插入元素”);
System.out.println(“[3]搜索”);
System.out.println(“[4]显示”);
System.out.println(“[5]删除”);
系统输出打印项次(“[0]停止”);
System.out.print(“输入选项:”);
e();
}
公共空间e(){
choice1=in.nextInt();
cls();
开关(选项1){
案例1:
{
System.out.println(“创建数组”);
System.out.println(“输入数组的限制:”);
limit1=in.nextInt();
如果(限制120){
System.out.println(“错误:超出最大限制”);
System.out.println(“返回主菜单”);
m();//循环到主菜单
}
如果(limit1>=5 | | limit1添加到案例1:
if (array != null) {
System.out.println("Already exists");
break;
}
如果(array==null)
或!=
您想知道的内容。