Answer:
Following are the code to this question:
public class ArrayMath//defining a class ArrayMath
{
public static void main(String[] args) //defining main method
{
int x[][]=new int[10][10]; //defining a 2D array
arrays(x);//calling a method arrays by passing an array
}
private static void arrays(int[][] x)//defining a method arrays
{
int odd_column_sum=0,sum_of_Elements=0,i,j,even=1;//defining integer variable
for(i=0;i<x.length;i++)//defining loop for columns
{
for(j=0;j<x[0].length;j++)//defining loop for rows
{
x[i][j]=i*j;//multiply the i and j value atore in array
}
}
System.out.println("::The 2D array :: ");//print message
for(i=0;i<x.length;i++)//defining loop for columns
{
System.out.print("\t");//use print method for line space and line break
for(j=0;j<x[0].length;j++)//defining loop for rows
{
System.out.printf("%d\t",x[i][j]); //print array values
}
System.out.println( );//print for line break
}
for(i=0;i<x.length;i++) //defining loop for Columns
{
for(j=0;j<x[0].length;j++) //defining loop for rows
{
if(even%2!=0)//defining if block for check odd number condition
{
odd_column_sum+=x[j][i];//add odd number of array
}
sum_of_Elements+=x[i][j];//add even number of array
}
even++;//increment even variable value by 1
}
System.out.println("The sum of Odd Columns:"+odd_column_sum);//print odd_column_sum value
System.out.println("The array elements :"+sum_of_Elements);//print sum_of_Elements value
}
}
Output:
please find attached file.
Explanation:
In the above-given code, a class "ArrayMath" is defined, inside the class the main method is declared, which define a 2D array "x", this stores 10 columns and 10 rows and at the last, we call the arrays method by passing an array as a variable.
In the arrays method, integer variable, "odd_column_sum, sum_of_Elements, i, j, and even" is defined, in which variable "i and j" is used in the loop for calculating value, even is used to check odd column and then store its value in the "odd_column_sum" variable, and add whole element value is added into the "sum_of_Elements" variable.