Code is copied!
Define a class to accept values into a 3×3 array and check if it is a special array. An array
is a special array if the sum of the even elements = sum of the odd elements.
Example:
A[][]={{ 4 ,5, 6}, { 5 ,3, 2}, { 4, 2, 5}};
Sum of even elements = 4+6+2+4+2 =18
Sum of odd elements= 5+5+3+5=18
Solution:
,,
import java.util.*;
class accept
{
public static void main(String args[])
{
int a[][],counteven=0,countodd=0;
a=new int[3][3];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array elements");
for(int i=0;i< 3;i++)
{
for(int j=0;j< 3;j++)
{
a[i][j]=sc.nextInt();
}
}
for(int i=0;i< 3;i++)
{
for(int j=0;j< 3;j++)
{
if(a[i][j]%2==0)
{
counteven+=a[i][j];
}
else{
countodd+=a[i][j];
}
}}
if(counteven==countodd)
{
System.out.println("Special array");
}
else{
System.out.println("Not a Special array");
}
}
}