【问题标题】:Why I can't use the isEmpty() method on vs code [closed]为什么我不能在 vs 代码上使用 isEmpty() 方法 [关闭]
【发布时间】:2021-04-08 20:26:54
【问题描述】:

我正在做一个实验前的任务,在其中他告诉我们实现许多方法,比如 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;
   }
}

【问题讨论】:

  • 您的工作是自己创建方法。这是练习。
  • @Zychoo 是的,我认为我必须做的是创建方法并使用,但我想确保它不是内置的。
  • 不,这是练习的目标@Mohamedchokor

标签: java visual-studio-code


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多