# How to determine the amount of specific elements in a two-dimensional array using a one-dimensional array?

For each row of the square array to find the sum of those elements that belong to the main and the secondary diagonal. Without the use of additional array, I have got such working code. How to apply to this one-dimensional array I do not know. Tried to copy the elements, which is calculated summ to a new array but got confused with the whole copy operation.
``````public class Main {

public static void main(String[] args) {
Scanner input1 = new Scanner(System.in);
int a;
int summ;
System.out.println(" For square array of size [a x a] enter value a: ");
a = input1.nextInt();
int array [][] = new int[a][a];
Scanner input2 = new Scanner(System.in);
int i = 0;
int j = 0;
System.out.println(" Enter "+ a + "item(s) in each row of the array:" );
for ( i = 0; i < a; i++)
for ( j = 0; j < a; j++)
array[i][j] = input2.nextInt();

// Output array
for(int [] t: array)
{
for(int b: t)
System.out.print(b+" ");
System.out.println();
}
int k = 0;
int b = a-1;
for (int z = 0; z < a; z++)
{
summ = array[z][k] + array[z][b];
if (b < a) {b--;}
if ( k < a) {
k++;}
System.out.println("Sum of values" + k + "string:" + summ);}
}}``````
June 10th 19 at 14:51