0% found this document useful (0 votes)
4 views19 pages

Assignemnt 9

Uploaded by

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

Assignemnt 9

Uploaded by

6725
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Atulya ghude

Question 1:

Program:
import java.util.*;
class Q1DDA
{
public static void main()
{
Scanner in=new Scanner(System.in);
int m,n, i,j,max=0,min=0,r=0,c=0,r1=0,c1=0;//declaring
System.out.println("enter the number of rows");
m=in.nextInt();
System.out.println("enter the number of coloumn");
n=in.nextInt();
int a[][]=new int[m][n];//doo=uble dimensional array
System.out.println("enter the no.inside matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=in.nextInt();
}

1
Atulya ghude

}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
min=a[0][0];//default value
max=a[0][0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(min>a[i][j])
{
min=a[i][j];
r=i;c=j;
System.out.println("Position rows="+r);//position
System.out.println("position coloumn="+c);
}
else if(max<a[i][j])
{
r1=i;c1=j;
max=a[i][j];
System.out.println("Position rows="+r1);
System.out.println("position coloumn="+c1);
}

2
Atulya ghude

}
}
System.out.println("Highest no="+max);
System.out.println("Lowest no="+min);

}
}
Input 1

Output 1

3
Atulya ghude

Input 2

Output 2

Input 3

Output 3

4
Atulya ghude

Question 2:

Program:
import java.util.*;
class Q2DiagonalDDA
{
public static void main()
{
Scanner in=new Scanner(System.in);
int i,j,r,col,de=0,dp=0,d=0;//declaring

System.out.println("enter the rows");


r=in.nextInt();
System.out.println("enter the coloum");//from the user
col=in.nextInt();
int a[][]=new int[r][col];
if(r==col)

System.out.println("Diagonal");
else
{

5
Atulya ghude

System.out.println("No diagonal");
}
System.out.println("enter the no matrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
a[i][j]=in.nextInt();
}
}
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
if(i==j)

de=de+a[i][j]; //addition

else if(i>j)
dp=de+a[i][j];
else if(i<j)

6
Atulya ghude

d=d+a[i][j];
}
}
System.out.println("lower="+d);//printing
System.out.println("middle="+ de);
System.out.println("upper="+ dp);

}
}
Input 1:

Output 1:

7
Atulya ghude

Input 2:

Output 2:

Input 3:

Output 3:

8
Atulya ghude

Question 3:

Program:
import java.util.*;
class Q3Diagonalzero
{
public static void main()
{
Scanner in=new Scanner(System.in);
int i,j,r,col;
System.out.println("enter the rows");
r=in.nextInt();
System.out.println("enter the coloum");
col=in.nextInt();
int a[][]=new int[r][col];
if(r==col)

System.out.println("Diagonal");
else
{
System.out.println("No diagonal");
System.exit(0);
}

9
Atulya ghude

System.out.println("enter the no matrix");


for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
a[i][j]=in.nextInt();
}
}
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
if(i==j)
a[i][j] = 0;
}

}
for(i=0;i<r;i++)//printing the output
{
for(j=0;j<col;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}

}
}

10
Atulya ghude

Input 1:

Output 1:

Input 2:

Output 2:

11
Atulya ghude

Input 3:

Output 3:

12
Atulya ghude

Question 4

Program:
import java.util.*;
class Q4DDA
{
public static void main()
{
Scanner in = new Scanner (System.in);
int i,j,r,c;
System.out.println("Enter the number of rows and columns");//from the user
r = in.nextInt();
c= in.nextInt();
int a[][] = new int[r][c];
System.out.println("Enter elements in the matrix");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j] = in.nextInt();
}
}
int sum =0;

13
Atulya ghude

for(i = 0; i<r; i++)


{
for(j = 0; j <c; j++)
{
if (i == 0 || j == 0 || i == r - 1 || j == c - 1)
sum = sum +a[i][j];//calculation
}
}
for(i = 0; i<r; i++)
{
for(j = 0; j< c; j++)
{
if (i == 0 || j == 0 || i == r - 1 || j == c - 1)//if condition
System.out.print(a[i][j] +" ");
else
System.out.print(" ");
}
System.out.println(" ");
}

System.out.println("The boundary sum is =" + sum);//output

}
}
Input 1:

14
Atulya ghude

Output 1

Input 2

Output 2

Input 3:

Output 3:

15
Atulya ghude

Question 5

Program:
import java.util.*;
class Q5DDA
{
public static void main()
{
Scanner in=new Scanner (System.in);
int i,j;
int a[][]=new int[4][4];//values
int t[][]=new int[4][4];
System.out.println("enter in the matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=in.nextInt();
}
}
for(i=0;i<4;i++)

16
Atulya ghude

{
for(j=0;j<4;j++)
{
t[i][j] =a[j][i];//storing the value
}
}
for(i=0;i<4;i++)//printing
{
for(j=0;j<4;j++)
{
System.out.print(t[i][j]+" ");
}
System.out.println();
}
}
}
Input 1

Output 1

17
Atulya ghude

Input 2

Output 2

Input 3

Output 3

18
Atulya ghude

19

You might also like