public static int f (int []a, int []b,int []c)
    {
        final int N=a.length;
        int j, k=0, g=0, t=0 ;
        for(int i=0;i<N;i++)
        {
          for (j=0;j<N;j++)
           if (b[j]==a[i])
             break;
          if (j==N)
          {
            c[t]=a[i];
            if (g==0 || c[t]>k)
            {
                k=c[t];
                g=1;
            }

            t++;
        }


    }
    return k;

i need to test it.
i true to write main method and i cannt do this without errors
need help
tnx .

Here's a little example:

public class A {
    public static void main(String a[]){
        print("Hello World.");
    }

    public static void print(String str){
        System.out.println(str);
    }
}

You'll have to include your main function, and your own function into a class. In Java everything has to be an Object/class, not like in C++ where we could had classes, and other small functions (a hybrid language).

So, try to create a class in which you'll put the static function public static void main(String a[]) which is the starting point of the program.

i wrote some main :

public static void main (String []args){
int[] arry= new a[];
 a[] = {1,1,2,3,3};
 b[]= {1,2,2,3,3};
 c[4]= {0,0,0,0,0};
 system.out.println(k);
}

the error : array dimension missing

Hi,
The porblem is at line number 2
while initializing the array you must provide the array size.
hence modify the line 2 as below

 int[] arry=new int[5]; //5 is the array size and it can be any number   

also at line 7 -->

 system.out.println(k); // k is not defined anywhere

hence your code will not compile.

if you are trying to print the array then iterate the array and print each element of the array during iteration.

if you just print the array using its name then you will not see the elements inside the array.System just prints the array object.

as you are creating array in java, you have to also specify the size of it.
Also you have to define type of it like,int,string,double....

So modify it...and run it again..

int[] arry= new a[];

It's totally wrong.
The new operator from Java requires, when instantiating a new object, to have as it's right operands the constructor of the required object you want to instantiate, which, in your case, it's int ( and than size, if allocating an array).
But, you can also declare an array of ints in a C++ like thing:

int array[]={0, 1, 2, 3, 4, 5};

Presumably, that's what you were looking for.

public class A{
    public static void main(String arg[]){
        int array[]={1, 2, 3, 4, 5, 6};
        for (int i=0;i<5;i++)
            print(Integer.toString(array[i]));
    }

    public static void print(String a){
        System.out.println(a);
    }
}

A small point:
although the declaration syntax int arr[] is perfectly valid, most standards prefer the form int[] arr That's the form you will find throughout the Java API source code.
The reason is that arr is an array of ints, as implied by the second form. The first form seems to suggest that there is an array of arrs that is an int.

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.