0% found this document useful (0 votes)
9 views4 pages

Learn It

Computer programmes

Uploaded by

xabali5204
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)
9 views4 pages

Learn It

Computer programmes

Uploaded by

xabali5204
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
You are on page 1/ 4

Question 1:

int P [ ]={ 12,14,16,18}; int Q[ ]={ 20,22,24};

Place all elements of P array and Q array in the array R one after the other.

(a) What will be the size of array R [ ] ? R.length = 7

(b) Write index position of first and last element?

Index of the first element =0

Index of the last element=6

Question 2:

If A[][] is a double dimensional array, calculate the number of rows( M) and number
of columns(C).

(a) int R= A.length;


(b) int C=A[0].length //each row is considering as a single dimensional array

If the matrix is given as an argument

class Sample

public int (int a[][])

//printing the matrix

for(int i=0;i<a.length;i++)

for(int j=0;j<a[0].length;i++) //or for(int j=0;j<a[i].length;i++)

System.out.println(a[i][j]+ “ ”);
}

System.out.println();

Question 3:

A square matrix is said to be Symmetric if the element of ith row is equal to the jth column.

Write a program to create a 3X3 matrix , display it and check whether it is a Symmetric
matrix or not.

Example:

1 2 3

2 4 5

3 5 6

import java.util.*;

class Symetric

public void check()

Scanner sc= new Scanner(System.in);

int A[][]=new int[3][3];

//storing elements in the matrix

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

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

System.out.println("Enter a number:");

A[i][j]=sc.nextInt();

//printing the original matrix

System.out.println("Original Matrix is:");

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

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

System.out.print(A[i][j]+"\t");

System.out.println();

//checking whether the matrix is Symmetric or not

int f=0;

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

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

if(A[i][j]!=A[j][i])//if not equal


{

f=1;

break;

if(f==0)

System.out.println("It is a Symmetric Matrix.");

else

System.out.println("It is not a Symmetric Matrix");

You might also like