Display the elements of the 2D array of 4x3
public class array_2d
The elements of the 2D array are
{
1 2 3
public static void main()
2 4 6
{
3 4 7
int data[][]={{1,2,3},{2,4,6},{3,4,7},{5,6,7}};
5 6 7
[Link]("The elements of the 2D array are ");
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
[Link](data[i][j]+"\t");
}
[Link]();
}
}
}
Display the elements of the 2D array of 2x3 using Scanner class
import [Link].*;
Enter the rows
public class array2D_Scanner
2
{
Enter the columns
public static void main()
3
{
Enter the values for 2D array
Scanner sc=new Scanner([Link]);
1
int i,j,rows,columns;
Enter the values for 2D array
[Link]("Enter the rows");
2
rows=[Link]();
Enter the values for 2D array
[Link]("Enter the columns");
3
columns=[Link]();
Enter the values for 2D array
int a[][]=new int[rows][columns];
4
for(i=0;i<rows;i++)
Enter the values for 2D array
{
5
for(j=0;j<columns;j++)
Enter the values for 2D array
{
6
[Link]("Enter the values for 2D array");
123
a[i][j]=[Link]();
456
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
}
}
Create a 2D array of size 2x3 and print square of all the odd numbers in the array
import [Link].*;
enter the numbers
public class array_2D_oddsum
1
{
enter the numbers
public static void main()
2
{
enter the numbers
Scanner sc=new Scanner([Link]);
3
int a[][]=new int[2][3];
enter the numbers
int i, j;
4
for(i=0;i<2;i++)
enter the numbers
{
5
for(j=0;j<3;j++)
enter the numbers
{
6
[Link]("enter the numbers");
odd number :1 and its square is : 1.0
a[i][j]=[Link]();
odd number :3 and its square is : 9.0
}
odd number :5 and its square is : 25.0
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j]%2!=0)
[Link]("odd number :"+a[i][j]+" and its square is : "+[Link](a[i][j],2));
}
}
}
}
WAP to input elements in a 2D array of size mxn and print the sum of all the number row wise and product of
all the elements column wise.
import [Link].*;
public class array2D_rowsum_colpro Enter the rows
{ 2
public static void main() Enter the columns
{ 2
Scanner sc=new Scanner([Link]); Enter the values for 2D array
int i,j,rows,columns,sum=0,pro=1; 1
[Link]("Enter the rows"); Enter the values for 2D array
rows=[Link](); 2
[Link]("Enter the columns"); Enter the values for 2D array
columns=[Link]();
3
int a[][]=new int[rows][columns];
Enter the values for 2D array
for(i=0;i<rows;i++)
{ 4
for(j=0;j<columns;j++) Sum of rows : 10
{ Product of columns : 24
[Link]("Enter the values for 2D array");
a[i][j]=[Link]();
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
sum=sum+a[i][j];
pro=pro*a[j][i];
}}
[Link]("Sum of rows : "+sum);
[Link]("Product of columns : "+pro);
}
}
WAP to input elements in a 2D array of size mxn and print the sum of all the number row wise.
import [Link].*;
public class array2D_each_rowsum Enter the rows
{ 2
public static void main() Enter the columns
{ 2
Scanner sc=new Scanner([Link]); Enter the values for 2D array
int i,j,rows,columns,sum; 1
[Link]("Enter the rows"); Enter the values for 2D array
rows=[Link](); 2
[Link]("Enter the columns");
Enter the values for 2D array
columns=[Link]();
3
int a[][]=new int[rows][columns];
Enter the values for 2D array
for(i=0;i<rows;i++)
{ 4
for(j=0;j<columns;j++) Sum of rows 1 : 3
{ Sum of rows 2 : 7
[Link]("Enter the values for 2D array");
a[i][j]=[Link]();
}
}
for(i=0;i<rows;i++)
{
sum=0;
for(j=0;j<columns;j++)
{
sum=sum+a[i][j];
}
[Link]("Sum of rows "+(i+1)+" : "+sum);
} }
}
WAP to input elements in a 2D array of size mxn and print the sum of all the number column wise.
import [Link].*; Enter the rows
public class array2D_each_colsum 2
{
Enter the columns
public static void main()
2
{
Scanner sc=new Scanner([Link]); Enter the values for 2D array
int i,j,rows,columns,sum; 1
[Link]("Enter the rows"); Enter the values for 2D array
rows=[Link](); 2
[Link]("Enter the columns"); Enter the values for 2D array
columns=[Link](); 3
int a[][]=new int[rows][columns]; Enter the values for 2D array
for(i=0;i<rows;i++) 4
{ Sum of columns 1 : 4
for(j=0;j<columns;j++) Sum of columns 2 : 6
{
[Link]("Enter the values for 2D array");
a[i][j]=[Link]();
}
}
for(j=0;j<columns;j++)
{
sum=0;
for(i=0;i<rows;i++)
{
sum=sum+a[i][j];
}
[Link]("Sum of columns "+(j+1)+" :
"+sum);
} }
}
WAP to input elements in a 2D array of size mxn and print the product of all the number row wise.
import [Link].*;
public class array2D_each_rowproduct Enter the rows
{ 2
public static void main() Enter the columns
{ 2
Scanner sc=new Scanner([Link]); Enter the values for 2D array
int i,j,rows,columns,pro; 1
[Link]("Enter the rows"); Enter the values for 2D array
rows=[Link](); 2
[Link]("Enter the columns");
Enter the values for 2D array
columns=[Link]();
3
int a[][]=new int[rows][columns];
for(i=0;i<rows;i++) Enter the values for 2D array
{ 4
for(j=0;j<columns;j++) Product of rows 1 : 2
{ Product of rows 2 : 12
[Link]("Enter the values for 2D array");
a[i][j]=[Link]();
}
}
for(i=0;i<rows;i++)
{
pro=1;
for(j=0;j<columns;j++)
{
pro=pro*a[i][j];
}
[Link]("Product of rows "+(i+1)+" : "+pro);
} }
}
WAP to input elements in a 2D array of size mxn and print the product of all the number column wise.
import [Link].*; Enter the rows
public class array2D_each_colproduct 2
{ Enter the columns
public static void main() 2
{ Enter the values for 2D array
Scanner sc=new Scanner([Link]); 1
int i,j,rows,columns,pro; Enter the values for 2D array
[Link]("Enter the rows"); 2
rows=[Link](); Enter the values for 2D array
[Link]("Enter the columns"); 3
columns=[Link](); Enter the values for 2D array
int a[][]=new int[rows][columns]; 4
for(i=0;i<rows;i++) Product of columns 1 : 3
{ Product of columns 2 : 8
for(j=0;j<columns;j++)
{
[Link]("Enter the values for 2D array");
a[i][j]=[Link]();
}
}
for(j=0;j<columns;j++)
{
pro=1;
for(i=0;i<rows;i++)
{
pro=pro*a[i][j];
}
[Link]("Product of columns "+(j+1)+" : "+pro);
} }
}