0% found this document useful (0 votes)
3 views7 pages

Araay

The document contains a Java program that initializes a 2D array, takes user input for its elements, and performs various operations such as calculating the sum of all elements, boundary elements, non-boundary elements, and diagonal sums. It also computes the product of all elements and checks if the array is 'special' based on the equality of the sum of even and odd elements. The program outputs the results of these calculations and displays the elements of the array in different formats.

Uploaded by

sainidaksh01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Araay

The document contains a Java program that initializes a 2D array, takes user input for its elements, and performs various operations such as calculating the sum of all elements, boundary elements, non-boundary elements, and diagonal sums. It also computes the product of all elements and checks if the array is 'special' based on the equality of the sum of even and odd elements. The program outputs the results of these calculations and displays the elements of the array in different formats.

Uploaded by

sainidaksh01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;

class array

void main()

//scanner class

Scanner Sc=new Scanner([Link]);

[Link]("enter array size ");

int n=[Link]();

int m=[Link]();

//array initialization

int A[][]=new int[n][m];

//input

[Link]("enter array elements ");

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

A[i][j]=[Link]();

//output

[Link]("array elements are");

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)
{

[Link](A[i][j]+"\t");

[Link]();

//sum of all elements

int sum=0;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

sum=sum+A[i][j];

[Link]("sum = "+sum);

//bounday element sum

int sumb=0;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

if((i==0)||(j==0)||(j==(m-1))||(i==n-1))

sumb=sumb+A[i][j];
}

[Link]("sum of boundary elements = "+sumb);

//non - bounday element sum

int sumnb=0;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

if((i==0)&&(j==0)&&(j==(m-1))&&(i==n-1))

{}

else

sumnb=sumnb+A[i][j];

[Link]("sum of boundary elements = "+sumnb);

//display bounday elements like them

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

{
if((i==0)||(j==0)||(j==(m-1))||(i==n-1))

[Link](A[i][j]+"\t");

else

[Link]("\t");

[Link]();

//non - bounday elements like them

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

if((i==0)&&(j==0)&&(j==(m-1))&&(i==n-1))

[Link]("\t");

else

[Link](A[i][j]+"\t");

[Link]();

}
//diagonal sum major

int summd=0;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

if(i==j)

summd=summd+A[i][j];

[Link]();

[Link]("the sum of major diagonal "+summd);

//diagonal sum minor

int sumnd=0;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

if(i+j==(n-1)||(i+j==(m-1)))

sumnd=sumnd+A[i][j];

[Link]();

[Link]("the sum of major diagonal "+sumnd);


//product of all elements

int prod=1;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

prod=prod*A[i][j];

[Link]("product = "+prod);

int sume=0,sumo=0;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

if(A[i][j]%2==0)

sume=sume+A[i][j];

else

sumo=sumo+A[i][j];

if(sumo==sume)

[Link]("It is a special array");

else

[Link]("It is not a special array");


}

You might also like