Loading
View RSS Feed

Angad Kumar Shukla's blog

Some Array Programs in Java

Rating: 13 votes, 4.62 average.

Program to print a SYMMETRIC Array.



Code:
import java.io.*;
class Array1
{
public static void main (String args[])throws IOException
	{int i,j,c=0,n;
InputStreamReader x=new InputStreamReader(System.in);
		BufferedReader y=new BufferedReader(x);
		System.out.println("ENTER THE DIMENSION OF ARRAY");
		n=Integer.parseInt(y.readLine());
		int a[][]=new int[n][n];
		int b[][]=new int [n][n];
		System.out.println("ENTER NOS IN AN ARRAY");
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				a[i][j]=Integer.parseInt(y.readLine());
			}
		}
				System.out.println("CONTENTS OF ARRAY ARE");
	for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				System.out.print(a[i][j]+" ");
			}
			System.out.println(" ");
		}
			for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				b[i][j]=a[j][i];
			}
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(a[i][j]==b[i][j])
				{
					c=c+1;
				}
			}
		}
		if(c==(n*n))
		{
			System.out.println("IT IS SYMMETRIC ARRAY");
		}
		else
		{
			System.out.println("IT IS NOT A SYMMETRIC ARRAY");
		}
		}
		}


Printing TRANSPOSE of an Array.





Code:
import java.io.*;
class Array2
{
	public static void main(String args[])throws IOException
	{
		int i,j;
		InputStreamReader x=new InputStreamReader(System.in);
		BufferedReader y=new BufferedReader(x);
		int a[][]=new int[3][3];
		int b[][]=new int[3][3];
		System.out.println("ENTER NOS IN AN ARRAY");
		for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++)
			{
				a[i][j]=Integer.parseInt(y.readLine());
			}
		}
			System.out.println("CONTENTS OF ARRAY ARE");
	for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++)
			{
				System.out.print(a[i][j]+" ");
			}
			System.out.println(" ");
		}
		for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++)
			{
				b[i][j]=a[j][i];
			}
		}
		for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++)
			{
				System.out.print(b[i][j]+" ");
			}
			System.out.println(" ");
		}
	}
}


Program to have STRING Array.





Code:
import java.io.*;
class Array3
{
	public static void main(String args[])throws IOException
	{
		String s;
		char b;
		char h;
		int d=0,c=0,i,j,l,k,n;
		InputStreamReader x=new InputStreamReader(System.in);
		BufferedReader y=new BufferedReader(x);
		System.out.println("ENTER THE NO. OF SENTENCES(upto 20)");
		n=Integer.parseInt(y.readLine());
		String st[]=new String[n];
		for(i=0;i<n;i++)
		{
		System.out.println("ENTER A STRING");
		st[i]=y.readLine();
		}
		for(i=n-1;i>=0;i--)
		{
			s=" "+st[i];
			l=s.length();
			for(j=l-1;j>=0;j--)
			{
				b=s.charAt(j);
				if(b!=' ')
			{
				c=c+1;
			}
			else
			{
				for(k=j;k<=j+c;k++)
				{
				h=s.charAt(k);
				d=(int)h;
				if((d>=97 && d<=122) || (d>=65 && d<=91) || h==' ')
				{
					System.out.print(h);
				}
				}
			
			c=0;
			}
		}
		}
		}
		}

Program to Print the content of n- dimensional array.




Code:
import java.io.*;
class Array4
{
public static void main (String args[])throws IOException
	{int i,j,p,k,l,n;
InputStreamReader x=new InputStreamReader(System.in);
		BufferedReader y=new BufferedReader(x);
		System.out.println("ENTER THE DIMENSION OF ARRAY");
		n=Integer.parseInt(y.readLine());
		int a[][]=new int[n][n];
		System.out.println("ENTER NOS IN AN ARRAY");
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				a[i][j]=Integer.parseInt(y.readLine());
			}
		}
				System.out.println("CONTENTS OF ARRAY ARE");
	for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				System.out.print(a[i][j]+" ");
			}
			System.out.println(" ");
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<(n-1);j++)
			{
				sm=a[i][j];
				
			}
		}
		}
		}

Program to get the SADDLE POINT Of an ARRAY using Java




Code:
import java.io.*;


class Array5
{
	public static void main(String args[])throws IOException
	{
		int i,j,k,l,q=0,w=0,q1=0,w1=0,n,p;

		InputStreamReader x=new InputStreamReader(System.in);
		BufferedReader y=new BufferedReader(x);
		System.out.println("ENTER DIMENSION OF ARRAY");
		n=Integer.parseInt(y.readLine());
		int a[][]=new int[n][n];
		System.out.println("ENTER NOS IN AN ARRAY");
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				a[i][j]=Integer.parseInt(y.readLine());
			}
		}
			System.out.println("CONTENTS OF ARRAY ARE");
	for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				System.out.print(a[i][j]+" ");
			}
			System.out.println(" ");
		}	
		for(j=0;j<n;j++)
		{
			i=0;
			if(a[i][j]<min)
			{
				min=a[i][j];
			}
			for(k=0;k<n;k++)
			{
				l=0;
				if(a[k][l]>max)
				{
					max=a[k][l];
				}
			}
			++i;
			++l;
		}
		I)
		System.out.println("SADDLE PT ):
		}
		}

Program to print the SUM OF ELEMENTS in a double dimensional array.




Code:
import java.io.*;	
class matrix
{
	int ar[][]=new int[5][5];
	int i,j,y;
	void input()throws IOException
	{
		InputStreamReader x=new InputStreamReader(System.in);
		BufferedReader y=new BufferedReader(x);
		System.out.println("ENTER NOS IN AN ARRAY");
		for(i=0;i<5;i++)
		{
			for(j=0;j<5;j++)
			{
				ar[i][j]=Integer.parseInt(y.readLine());
			}
		}
		}
		int sum(int i)
		{
			int s=0;
			for(j=0;j<5;j++)
			{
				s=s+ar[i][j];
			}
			return s;
		}
		void print()
		{
			for(i=0;i<5;i++)
			{
				for(j=0;j<5;j++)
				{
					System.out.print(ar[i][j]+" ");
				}
				System.out.println();
			}
		}
		void sumrows()
		{
			for(i=0;i<5;i++)
			{
				y=sum(i);
				System.out.println("SUM OF ROW "+(i+1)+" IS "+y);
			}
		}
		public static void main(String args[])throws IOException
		{
			matrix a=new matrix();
			a.input();
			a.print();
			a.sumrows();
		}
		}

Submit "Some Array Programs in Java" to Digg Submit "Some Array Programs in Java" to del.icio.us Submit "Some Array Programs in Java" to StumbleUpon Submit "Some Array Programs in Java" to Google

Categories
Java

Comments

  1. indies's Avatar
    these progranms will be of immense help. i am trying for off campussing. thsi will help me.



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.