为什么我不能在 vs 代码上使用 isEmpty() 方法

时间:2021-04-08 20:26:54

标签: java visual-studio-code

我正在做一个实验前的作业,他告诉我们要实现许多方法,比如 isEmpty(int[] arr)。 (我将在下面包含这个问题) 我尝试导入许多库,但没有任何效果,并尝试在网上搜索修复程序,但找不到有关我的问题的任何信息,我开始怀疑自己,也许我们必须创建该函数而它不是内置的,但是他在问题中说要实现,所以它应该是内置的。 提前感谢您的帮助。

错误信息: 未定义类型 exercice1 的方法 isEmpty(int[])。

问题:

Write a java program that implements the following functions:
1. Method isEmpty(int [] arr) returns true if the array arr contains no elements otherwise false.
2. Method isFull(int [] arr) returns true if the array arr contains elements as the number of array length.
3. Method display(int [] arr) that displays the elements of the array arr.
4. Method InsertElement(int [] arr, int v, int i) add an element of value v to the array arr at position i.
Note: You must check first if the array is full or not before inserting the new element.
5. Method DeleteElement(int [] arr, int v) delete the element from array arr if it’s found otherwise return false.
Note: You must check first if the array is empty or not before the deletion.
6. Method OccurrenceNb(int [] arr, int v) returns the number of occurrence of certain number.
7. Method deleteAllEven(int [] arr) return the same array after deleting all the even numbers from the array.
8. Method EvenOrOdd(int [] arr) returns true if the number of even numbers is greater than the number of odd numbers otherwise false.

我的代码:

import java.util.*;

public class exercice1 {

   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);

      System.out.println("Enter an array to check if it's empty");
      System.out.print("Enter the size of the array: ");
      int n1 = input.nextInt();
      int arr1[] = new int[n1];
      readArray(arr1, n1);
      System.out.println(isEmpty(arr1));

   }

   public static int[] readArray(int[] arr, int n) {
      for (int i = 0; i < n; i++) {
         Scanner input1 = new Scanner(System.in);
         arr[i] = input1.nextInt();
      }
      return arr;
   }
}

1 个答案:

答案 0 :(得分:1)

据我所知,您应该创建自己的 isEmpty(int [] arr) 方法,然后在您的代码中使用它。

相关问题