-2

I have table like this:

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

I have created 4 functions that is: void alpha_int(), int binery( int a), float d( int x), float e(float b), float f(float f). My one array is revolving in each function, firstly i am doing index wise for calculation up to function e(), but i am failed how to send complete array to function f() because it is taking avg.

code strtgy:

//----------------
//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]; 
         }
     }

}
user3508182
  • 457
  • 1
  • 4
  • 13

2 Answers2

1

That's because you've defined the argument to be of type float, which is a single 32-bit floating point number, not an array. Try defining it as float[] or int[] instead.

Also, you must return something in f, as the function's type is defined to be float.

kviiri
  • 3,282
  • 1
  • 21
  • 30
  • i did this it is now giving me error cannot cast from int[] to float in function d(); i in d() function i am doing like this: float array = (float)x; – user3508182 May 10 '14 at 07:25
  • @user3508182, you need to have correct return types for all functions, naturally. If you have a call like `a(b(c(d)))`, `a` must accept the return value of `b` as an argument, `b` must accept the return value of `c` as an argument and `c` must accept `d` as an argument. – kviiri May 10 '14 at 07:27
  • surely m doing this. but i cannot place f(a(d(array)); inside for loop in void alpha_int(); just give idea how shell i send complete "e" (from table ) to f(...) function??? – user3508182 May 10 '14 at 07:34
  • complete e means all values in array of function e()? – user3508182 May 10 '14 at 07:35
  • `e` returns just one float. Make it return the entire array if that's what you want. Alternatively, make your call different (put it in a loop). – kviiri May 10 '14 at 08:02
0

My one array is revolving in each function,

You are storing data of various types into one array? You can instead go for a HashMap<> and use key-value pairs. Your methods can then retrieve different arrays based on on keys. Like so:

HashMap<String, int[]> map = new HashMap<String, int[]>();  

and then work with it as:

binary( map.get("binary") );  

later, set your result as :

map.put("binary",yourArrayName);  
return someValueBasedOnComputation;

Looks much cleaner, in my limited knowledge :)
Source: Store an array in HashMap

Community
  • 1
  • 1
An SO User
  • 24,612
  • 35
  • 133
  • 221