0% found this document useful (0 votes)
102 views

VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1

The document contains code for four Java programs that perform operations on matrices. The first program rotates a matrix and calculates the sum of elements at the four corners. The second checks if a matrix is symmetric. The third prints the original and mirrored version of a matrix. The fourth converts integer numbers less than 10,000 into their word representations in English.

Uploaded by

Natania Prasad
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)
102 views

VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1

The document contains code for four Java programs that perform operations on matrices. The first program rotates a matrix and calculates the sum of elements at the four corners. The second checks if a matrix is symmetric. The third prints the original and mirrored version of a matrix. The fourth converts integer numbers less than 10,000 into their word representations in English.

Uploaded by

Natania Prasad
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/ 11

import java .util.

*;//java package included

public class matrix

public static void main ( String args[])

Scanner sc=new Scanner( System.in);

System.out.println( "Enter the value of M");

int M=sc.nextInt();

if (M>2&&M<10)

int s=0;//variable initialisation

int A[][]=new int [M][M];

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

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

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

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

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


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

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

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

System.out.println("" );

System.out.println( "Rotated matrix is:");

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

for ( int j=(M-1);j>=0;j--)

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

if( i==0&&j==(M-1)||j==0&&i==(M-1)||i==(M-1)&&j==(M-1)||i==0&&j==0)

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

System.out.println("" );

}
System.out.println(" The sum of the elements at the four corners is : "+ s);// the sum is displayed

else

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

mport java .util.*;//java package included

public class symmetry

public static void main ( String args[])

Scanner sc=new Scanner( System.in);

System.out.println( "Enter the value of M");

int M=sc.nextInt();

int A[][]=new int [M][M];

int c=0;//variable initialisation

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

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


{

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

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

System.out.println( "Inputted matrix is:");

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

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

System.out.print(A[i][j]);//displays the inputted matrix

System.out.println( "");

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

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

if( A[i][j]!=A[j][i])

c=0;

}
}

if(c==1)

System.out.println(" It is a symmetric matrix");

else

System.out.println(" It is not a symmetric matrix");

import java .util.*;//java package included

public class mirror

public static void main ( String args[])

Scanner sc=new Scanner( System.in);

System.out.println( "Enter the value of M");

int M=sc.nextInt();

if (M>2&&M<280)

int s=0;//variable initialisation

int A[][]=new int [M][M];


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

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

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

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

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

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

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

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

System.out.println("" );

System.out.println( "Mirrored matrix is:");

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

for ( int j=2;j>=0;j--)

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

System.out.println("" );

import java .util.*;//java package included

public class natural

public static void main ( String args[])

Scanner sc=new Scanner( System.in);

System.out.println( "Enter a integer less than 10,000");

int n=sc.nextInt();

int a[]=new int[4];

String ar[]={"ONE" ,"TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};//array


initialisation

String ar1[]={"TEN","TWENTY","THIRTY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY"};

String ar2[]={ "ELEVEN


","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN"};

int n1=n,i=4;
while(n1>0)

a[--i]=n1%10;

n1=n1/10;

while(i!=0)

a[--i]=0;

if(a[0]!=0)

System.out.print( ar[a[0]-1]+" "+"THOUSAND"+" ");

if(a[1]!=0)

System.out.print( ar[a[1]-1]+" "+"HUNDRED"+" ");

if(a[2]!=0)

if(a[2]>=2)

System.out.print( ar1[a[2]-1]+" ");

}
if(a[2]==1)

System.out.print( ar2[a[2]-1]+" ");

if (a[2]!=0&&a[3]!=0)

System.out.print( ar[a[3]-1]+" ");

else

if (a[2]==0&&a[3]!=0)

System.out.print( ar[a[3]-1]+" ");

System.out.println( "Enter another integer less than 10,000");

int m=sc.nextInt();

int m1=m;

i=4;//variable initialisation

while(m1>0)

a[--i]=m1%10;

m1=m1/10;
}

while(i!=0)

a[--i]=0;

if(a[0]!=0)

System.out.print( ar[a[0]-1]+" "+"THOUSAND"+" ");

if(a[1]!=0)

System.out.print( ar[a[1]-1]+" "+"HUNDRED"+" ");

if(a [2]!=0)

if(a[2]>=2)

System.out.print( ar1[a[2]-1]+" ");

if(a[2]==1)

System.out.print( ar2[a[2]-1]+" ");


}

if (a[2]!=0&&a[3]!=0)

System.out.print( ar[a[3]-1]+" ");

else

if (a[2]==0&&a[3]!=0)

System.out.print( ar[a[3]-1]+" ");

You might also like