Hi guys...
Thanks for viewing my thread and hopefully u could reply a thing.

i have this:
input: -i 2,3,4,5

public class Main
{

  
    public static void main (String [] args)
    {  
      static int value[];
      static no_of_parameter;
      for (int i=0;i<args.length;i++)
       {
           if (args[i].equals ("-i"))
           {
             String value_str = new String();
             // assign data values automatically to data by commas
              StringTokenizer s = new StringTokenizer (value_str,",");
              // count parameter
              no_of_parameter = value_str.replaceAll("[^,]","").length();
              no_of_parameter++; // as an array size
              value = new int [no_of_parameter];
              int k =0;
              while (s.hasMoreTokens())
               {
		value[k]=Integer.parseInt(s.nextToken());
                 k++;
               }
             }
        
         generate (value[],no_of_parameter);//how can i pass value in array?
    }
  generate (value_array_list,no_of_parameter)
   {
     //operate an array for value and parameter
   }

}

Recommended Answers

All 6 Replies

remove those brackets from the end of the variable name, both when calling the method and in the declaration. In the declaration, place them after int, not after value (they both work but this way is clearer).

Edit: And I hope that that "generate" signature is not a serious attempt.

remove those brackets from the end of the variable name, both when calling the method and in the declaration. In the declaration, place them after int, not after value (they both work but this way is clearer).

hahaha....

sorry if u dont understand my point.its my bad.

my question is i want to pass value[] to generate ();

And I said to remove the brackets.

I.E. not

int value[] = ...
// or
generate(value[]...

but rather

int[] value = ...
// and
generate(value...

And, show me the real method signature for generate, as I hope that what you showed above is simply some psedo-code fill-in. If its not pseudo code, then compare that signature with the "main" signature and tell me what you think is missing (besides static although being called from main it needs to be that too), and your local variables in main should not be static.

Have you ever done anything in Java, or are you just throwing things around from PHP, or something, and trying them in Java directly. Because the more I llok at that code, the more it looks like something copied, and then modified by someone who has no clue what they're doing.

If you are just starting then go to the official tutorials and work through those before you attempt anything else.

And I said to remove the brackets.

I.E. not

int value[] = ...
// or
generate(value[]...

but rather

int[] value = ...
// and
generate(value...

And, show me the real method signature for generate, as I hope that what you showed above is simply some psedo-code fill-in. If its not pseudo code, then compare that signature with the "main" signature and tell me what you think is missing (besides static although being called from main it needs to be that too), and your local variables in main should not be static.

Have you ever done anything in Java, or are you just throwing things around from PHP, or something, and trying them in Java directly. Because the more I llok at that code, the more it looks like something copied, and then modified by someone who has no clue what they're doing.

If you are just starting then go to the official tutorials and work through those before you attempt anything else.

for (Iterator it = binary_list.iterator(); it.hasNext(); )
        { 
          count=1;
          String s = (String)it.next();
     //operate an array for value and parameter
     for(int i=0;i<no_of_parameter;i++)
        if (s.charAt(i)=='1') count=count*value[i];//actually i want to use this data
        }
   }

im new leaner and learning through the exercise is my way in learning.trying to understand other peoples' code as well...
thanks for advice.really appreciate that!

if (s.charAt(i)=='1') count=count*value[i];//actually i want to use this data

Okay? That is how you access a single element of an array (the reason for the brackets containing an int index). That has nothing to do with referencing the array as a whole.

Like I said, go through those tutorials.

And I said to remove the brackets.

I.E. not

int value[] = ...
// or
generate(value[]...

but rather

int[] value = ...
// and
generate(value...

And, show me the real method signature for generate, as I hope that what you showed above is simply some psedo-code fill-in. If its not pseudo code, then compare that signature with the "main" signature and tell me what you think is missing (besides static although being called from main it needs to be that too), and your local variables in main should not be static.

Have you ever done anything in Java, or are you just throwing things around from PHP, or something, and trying them in Java directly. Because the more I llok at that code, the more it looks like something copied, and then modified by someone who has no clue what they're doing.

If you are just starting then go to the official tutorials and work through those before you attempt anything else.

for (Iterator it = binary_list.iterator(); it.hasNext(); )
        { 
          count=1;
          String s = (String)it.next();
     //operate an array for value and parameter
     for(int i=0;i<no_of_parameter;i++)
        if (s.charAt(i)=='1') count=count*value[i];//actually i want to use this data
        }
   }

im new leaner and learning through the exercise is my way in learning.trying to understand other peoples' code as well...
thanks for advice.really appreciate that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.