如何在 2D ArrayList 中使用 .set 方法修复编译时错误

问题描述 投票:0回答:0

为了一个项目,我打算为“接下来会发生什么”微积分创建一个计算器,我偶然发现了一个我无法理解的错误。

在下面发布的代码中,我使用 IntegerDifferentialSetCalculus 类(忽略长标识符和过度使用 Pascal Case)来查找序列中的下一个(例如:[2,5,10])。为此,我必须找到集合的“集合导数”,直到显示计算机可以继续的恒定模式。我在方法 GetterNextTerm 中遇到问题,其中涉及 .set 的行在我的 IDE 中给我一个错误。你们有任何潜在的解决方案吗?谢谢! (另外,GetterNextTerm方法底部的return 1是一个占位符)

class IntegerDifferentialSetCalculus {
    public ArrayList<Integer> GetterFirstDerivative(ArrayList<Integer> CustomSet) {
        ArrayList<Integer> Derivative = new ArrayList<Integer>();
        for(int counter=1; counter<CustomSet.size(); counter++) {
            Derivative.add(CustomSet.get(counter)-CustomSet.get(counter-1));
        }
        return Derivative;
    }
    public ArrayList<Integer> GetterNTHderivative(ArrayList<Integer> CustomSet, int Order) {
        ArrayList<Integer> NTHderivative = CustomSet;
        for(int counter=1; counter<=Order; counter++) {
            IntegerDifferentialSetCalculus Derivatives = new IntegerDifferentialSetCalculus();
            NTHderivative = Derivatives.GetterFirstDerivative(NTHderivative);
        }
        return NTHderivative;
    }
    public Boolean GetterConstantPattern(ArrayList<Integer> CustomSet) {
        IntegerDifferentialSetCalculus Constant = new IntegerDifferentialSetCalculus();
        HashSet<Integer> OnlyOne = new HashSet<Integer>();
        for(int counter=0; counter<CustomSet.size()-1; counter++) {
            OnlyOne.add(Constant.GetterFirstDerivative(CustomSet).get(counter));
        }
        if(OnlyOne.size()==1) {
            return true;
        } else {
            return false;
        }
    }
    public Integer GetterNextTerm(ArrayList<Integer> CustomSet) {
        IntegerDifferentialSetCalculus CompositeSets = new IntegerDifferentialSetCalculus();
        ArrayList<ArrayList<Integer>> DerivativesList = new ArrayList<ArrayList<Integer>>();
        DerivativesList.add(CustomSet);
        int counter=1;
        while(CompositeSets.GetterConstantPattern(CompositeSets.GetterNTHderivative(CustomSet, counter-1))==false) {
            DerivativesList.add(CompositeSets.GetterNTHderivative(CustomSet, counter));
            counter++;
        }
        DerivativesList.add(CompositeSets.GetterNTHderivative(CustomSet, counter));
        DerivativesList.set(DerivativesList.size()-1,DerivativesList.get(DerivativesList.size()-1).add(DerivativesList.get(DerivativesList.size()-1).get(0)));
        ArrayList<Integer> One23 = new ArrayList<Integer>();
        System.out.println(DerivativesList);
        return 1;
    }
}
java multidimensional-array arraylist
© www.soinside.com 2019 - 2024. All rights reserved.