Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将数组从函数传递到从属函数_Java - Fatal编程技术网

Java 如何将数组从函数传递到从属函数

Java 如何将数组从函数传递到从属函数,java,Java,我有这样的桌子: alphabet binery integer d(in rad sin(integer)*100 e f a1 1010 10 41 70.6 46.3 a2 0011 3 14 57.06

我有这样的桌子:

alphabet     binery      integer      d(in rad sin(integer)*100         e       f
a1            1010       10           41                              70.6     46.3
a2            0011       3            14                              57.06    37
我创建了4个函数:void alpha_int()、int binery(inta)、float d(intx)、float e(float b)、float f(float f)。 我的一个数组在每个函数中都是旋转的,首先我对函数e()进行索引计算,但我无法将完整数组发送到函数f(),因为它取平均值

代码标准:

//----------------
//skipped theportion
//.............
void alpha_int()
{
    int [] a = new int [100];

    for(int i=1; i<=6;i++){
    {
       System.out.print("a"+i+"  "+binery(arra[i])+" "+array[i]+" "+d(array[i])+" "+e(d(array[i])));
    }

  f(a(d(array));   // gives error 
}
int binery( int a){
 // successfully complete
  return a;
}
float d( int x){
// did som work 
 return x;

}
 float e(float b){
// operations peformed
   return b;
}

 float f(float f){   // problem in sending complete array
     for( int i=1; i<f.length;i++){
         for(int j=1;j<f,length;j++){
            f[i]= f[i]+f[j]; 
         }
     }

}
//----------------
//跳过部分
//.............
void alpha_int()
{
int[]a=新的int[100];

对于(int i=1;i这是因为您已将参数定义为
float
类型,它是一个32位的浮点数,而不是数组。请尝试将其定义为
float[]
int[]

另外,您必须
返回
f
中的
内容,因为函数的类型定义为
float

我的一个数组在每个函数中旋转

您正在将各种类型的数据存储到一个数组中?您可以使用
HashMap
并使用键值对。然后,您的方法可以基于键值检索不同的数组。如下所示:

HashMap<String, int[]> map = new HashMap<String, int[]>();  
稍后,将结果设置为:

map.put("binary",yourArrayName);  
return someValueBasedOnComputation;
就我所知,看起来干净多了:)

来源:

我这样做了,现在它给了我一个错误,不能在函数d()中从int[]转换为float;我在函数d()中是这样做的:float array=(float)x;@user3508182,当然,所有函数都需要正确的返回类型
a
必须接受
b
的返回值作为参数,
b
必须接受
c
的返回值作为参数,
c
必须接受
d
作为参数。我当然会这样做。但我不能将f(a(d(数组)),放在for循环内部,在void alpha_int();只要告诉我shell如何将完整的“e”(从表中)发送到f(…)函数???完整的e表示函数e()数组中的所有值?
e
只返回一个浮点值。如果需要的话,让它返回整个数组。或者,让调用不同(放在循环中)。
map.put("binary",yourArrayName);  
return someValueBasedOnComputation;