Implement the selfDot method below, which takes as input an array of integers an
ID: 3576701 • Letter: I
Question
Implement the selfDot method below, which takes as input an array of integers and returns the sum of the each of the elements squared. An example main method, as well as corresponding output, is supplied - you cannot this method, and the output when the program is run must conform exactly to the sample output./* sample run: 14 125 */public static void main(String args[]) {int nums1[] = {1, 2, 3}; int nums2[] = {10, 5}; System.out.println(selfDot(nums1));//1*1 + 2*2 + 3*3 System.out.println(selfDot(nums2);//10*10 + 5*5}//put your selfDot method hereExplanation / Answer
public static int selfDot(int arr[])
{
int sum=0; //to store final addition
for(int i=0;i<arr.length;i++)
{
sum+=(arr[i]*arr[i]); //square of each element and then add to previous sum
}
return sum; //return final result.
}