首页 > 解决方案 > 处理:如何使一个函数找到我的数组的二次公式的结果?

问题描述

我有一个任务要做,不知道怎么做。

给出的是一个二次方程:

y = a*x*x + b*x + c

到目前为止,这就是我的代码:

void setup(){
    println(quadratic(4, 6, 1));
}

float quadratic(float a, float b, float c){
    return (-b + sqrt( b*b - 4*a*c)) / (2*a);
}

我必须编写一个函数,将系数作为参数,将结果作为数组。

我只是不知道如何制作一个数组。

非常感谢你!

标签: javaarraysprocessing

解决方案


我建议在谷歌上搜索“处理数组”或“Java 数组”之类的内容以获得大量结果。

处理参考是一个很好的起点。是 Processing 中数组的参考,它包含如下示例代码:

int[] numbers = new int[3];
numbers[0] = 90;  // Assign value to first element in the array
numbers[1] = 150; // Assign value to second element in the array
numbers[2] = 30;  // Assign value to third element in the array
int a = numbers[0] + numbers[1]; // Sets variable 'a' to 240
int b = numbers[1] + numbers[2]; // Sets variable 'b' to 180 

无耻的自我推销:这里有一个关于Processing中的数组的教程。


推荐阅读