0% found this document useful (0 votes)
23 views9 pages

Theory Programs

Uploaded by

all3n.paul
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)
23 views9 pages

Theory Programs

Uploaded by

all3n.paul
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/ 9

import java.util.

*;

class Boundary

public static void main ()

Scanner sn= new Scanner (System.in);

System.out.println ("Enter the elements");

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

int i=0;

int j=0;

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

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

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

System.out.println ("Boundary elements");

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

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

if (i==0 || i==2 || j==0 || j==2)

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


else

System.out.print ("\t");

System.out.println ();

import java.util.*;

class Transpose

public static void main ()

Scanner sn= new Scanner (System.in);

System.out.println ("Enter no. of rows");

int n= sn.nextInt();

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

System.out.println ("Enter the elements");

int i=0;

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

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

{
A[i][j]= sn.nextInt();

System.out.println ("Transposed matrix");

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

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

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

System.out.println ();

import java.util.*;

class Character_Pattern

public static void main ()

Scanner sn= new Scanner (System.in);


System.out.println ("Enter m");

int m= sn.nextInt();

if (m<3 || m>9)

System.out.println ("Invalid input");

System.exit(0);

System.out.println ("Enter 3 characters");

char ch1= sn.next().charAt(0);

char ch2= sn.next().charAt(0);

char ch3= sn.next().charAt(0);

char A[][]= new char [m][m];

int i=0;

int j=0;

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

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

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

A[i][j]= ch3;

else

A[i][j]= ch2;

}
A[0][0]= ch1;

A[0][m-1]= ch1;

A[m-1][0]= ch1;

A[m-1][m-1]= ch1;

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

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

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

System.out.println ();

import java.util.*;

class Arrange

public static void main ()

Scanner sn= new Scanner (System.in);

System.out.println ("Enter m and n");

int m= sn.nextInt();

int n= sn.nextInt();

if (m<2 || m>9 || n<2 || n>9)


{

System.out.println ("Invalid input");

System.exit(0);

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

int i=0;

int j=0;

System.out.println ("Enter the elements");

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

for (j=0; j<n; j++)

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

System.out.println ("Original matrix");

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

for (j=0; j<n; j++)

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

System.out.println ();

}
System.out.println ("Arranged matrix");

int p= m*n;

int B[]= new int [p];

int C[]= new int [p];

int P[]= new int [p];

int k=0;

int f=0;

int t=0;

int x=0;

int y=0;

int a=0;

int b=0;

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

for (j=0; j<n; j++)

B[k++]= A[i][j];

k=0;

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

for (j=1; j<=B[i]; j++)

{
if (B[i]%j==0)

f++;

if (f>2)

C[x++]= B[i];

a=x;

else

P[y++]= B[i];

f=0;

x=0;

y=0;

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

B[i]= C[x++];

for (i=a; i<p; i++)

B[i]= P[y++];

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

{
for (j=0; j<n; j++)

A[i][j]= B[k++];

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

for (j=0; j<n; j++)

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

System.out.println ();

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy