array programs | PDF | Computer Programming | Software Engineering
0% found this document useful (0 votes)
3 views11 pages

array programs

Uploaded by

dithya07
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
3 views11 pages

array programs

Uploaded by

dithya07
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 11

Program 1:

//changing the matrix order and position of elements

import java.util.*;

class programarray

public static void main(String args[])

Scanner in=new Scanner(System.in);

System.out.println("Enter the number of rows and columns");

int m=in.nextInt();

int n=in.nextInt();

if(m<2||m>10)

System.out.println("Order is out of range");

System.exit(0);

if(n<2||n>10)

System.out.println("Order is out of range");

System.exit(0);

int i,j;

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

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

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

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

a[i][j]=in.nextInt();

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

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

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

System.out.print(a[i][j]+" ");

System.out.println();

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

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

for(i=m-1;i>=0;i--)

System.out.print(a[i][j]+" ");

System.out.println();

}
//changing the matrix order and position of elements

import java.util.*;

class programarray

public static void main(String args[])

Scanner in=new Scanner(System.in);

System.out.println("Enter the number of rows and columns");

int m=in.nextInt();

int n=in.nextInt();

if(m<2||m>10)

System.out.println("Order is out of range");

System.exit(0);

if(n<2||n>10)

System.out.println("Order is out of range");

System.exit(0);

int i,j;

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

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

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

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

{
a[i][j]=in.nextInt();

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

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

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

System.out.print(a[i][j]+" ");

System.out.println();

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

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

for(i=m-1;i>=0;i--)

System.out.print(a[i][j]+" ");

System.out.println();

//design using array


import java.util.*;

class progdesign

public static void main(String args[])

Scanner in=new Scanner(System.in);int i,j;

System.out.println("Enter the order of the matrix");

int n=in.nextInt();

char arr[][]=new char[n][n];

System.out.println("Enter the characters one by one");

char a,b,c;

a=in.next().charAt(0);

b=in.next().charAt(0);

c=in.next().charAt(0);

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

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

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

arr[i][j]=a;

else if(i==0||j==0 || i==n-1 ||j==n-1)

arr[i][j]=b;

else

arr[i][j]=c;
}

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

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

System.out.print(arr[i][j]+" ");

System.out.println();

//selection sort technique

import java.util.*;

class prog17a

public static void main (String args[])

Scanner in=new Scanner(System.in);

int i,j,t,min;

int num[]=new int[10];

System.out.println("Enter 10 different numbers in the array");

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

num[i]=in.nextInt();

}
for(i=0;i<9;i++)

min=i;

for(j=i+1;j<10;j++)

if(num[j]<num[min])

min=j;

t=num[i];

num[i]=num[min];

num[min]=t;

System.out.println("The numbers arranged in ascending order are:");

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

System.out.println(num[i]);

}
// linear searching in single dimensional array

import java.util.*;

class linearsda

public static void main(String args[])

Scanner in=new Scanner(System.in);int i;int found=0;

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

int m=in.nextInt();

int a[]=new int[m];

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

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

a[i]=in.nextInt();

System.out.println("Enter the element to be searched");

int key=in.nextInt();

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

if(a[i]==key)

found=1;

break;

if(found==1)

{
System.out.println(key+" is present at "+(i+1)+" position ");

else

System.out.println("The element is not present");

//replace the vowels by next corresponding vowel and form a new word

import java.util.*;

class encrypt

public static void main(String args[])

Scanner in=new Scanner(System.in);

System.out.println("Enter a string ");

String s=in.nextLine();char c; String str="";

int n=s.length();

String st=s.toUpperCase();

System.out.println(st);

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

c=st.charAt(i);
if(c=='A')

str=str+'E';

else if(c=='E')

str=str+'I';

else if(c=='I')

str=str+'O';

else if(c=='O')

str=str+'U';

else if(c=='U')

str=str+'A';

else

str=str+c;

System.out.println("The altered string is" + str);

You might also like