this was the instructions...
"Write a short Java program that takes two arrays a and b of length n storing int values, and return the dot product of a and b. That is, it returns an array c of length n such that c = a . b, for i = 0, 1, ..., n - 1." The program must ask the user for the length of the arrays and the integers in both arrays.

and i thought i was done..but i keep getting "no main classes found" ..is it because i am using

public static int [] returnArray( int a[], int b[] )

instead of

public static void main(String args[])

how can i fix my program and make it work fine...

here is my code

public class Arrays {
public static int [] returnArray( int a[], int b[] )
{
int c[] = null;
for(int i =0; i< a.length; i++ )
{
c[i]+=( a[i]+b[i] );
}
return c;

}
}

Recommended Answers

All 2 Replies

You need to create a main class file or add a main class to your current file in order for it to run.

All you need to do to get your code to run is add a main class inside your

public class arrays {
}

Inside of the main class you need to call the code you wrote like this.

public static void main(String[] args){

    Scanner input = new Scanner(System.in);
 //the scanner is for reading input.

    int[] a = new int[];
    int[] b = new int[];
    int final = new int;

 // you will have to figure out how to read the users inpuut and set it equal to an array slot
    array = returnArray(a, b);

    //Your print statements here
}

you have three errors that I can see on line 2 and 7. see how far you can get from here. (;

in line 2 the return does not have to be an array because the dot product is one number and in line 7 in order to solve for the dot product you need to times a time b and then add it two your result.

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.