Task3 Array copying into another Array

public class Copy1Array2another {

/**
* @param args
*/
public static void main(String[] args) {

int[] oldArray={1,3,4}, newArray;
// Let’s pretend we filled up oldArray and initialized newArray here
// Now, copy them over
newArray=new int[2];
System.arraycopy(oldArray, 0, newArray, 0, 2);
System.out.println(“displaying old array”);
for(int i=0;i<3;i++)
{
System.out.println(oldArray[i]);
}
System.out.println(“displaying new array”);
for(int i=0;i<2;i++)
{
System.out.println(newArray[i]);
}
}

}

Task2 Remove an element with in an Array

import java.util.*;

public class ArrayEx {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] intArray = new int[] {1, 6, 0, 4, 2, 8, 7, 5, 9, 3};

int[] arrayCopy = new int[intArray.length];
System.out.println(“entered”);
System.arraycopy(intArray, 0, arrayCopy, 0,intArray.length);
Arrays.sort(arrayCopy);
for (int i = 0; i < 4; i++)
System.out.println(arrayCopy[i]);
int[] x=Arrays.copyOf(arrayCopy, 4);
for (int i = 0; i < 4; i++)
System.out.println(“x=”+x[i]);
// String s=”hai”;
StringBuffer buf=new StringBuffer(“raju”);
String rev=buf.reverse().toString();
String yourString=”hi hello hi hi”,naga;
System.out.println(yourString);
naga = yourString.replaceAll(“\\s+”, ” “);
System.out.println(naga);
System.out.println(rev);
}

}

task1 Matrix Program

program for finding entered triangle is a Upper triangular Matrix/Lower triangular  Matrix/Diagonal Matrix/ Non-triangular Marix

import java.util.Scanner;
public class Matrixprogram {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int i,j,c1=0,k1=0,c2=0,k2=0,n = 0,d=0,d1=0;
Scanner in = new Scanner(System.in);
System.out.println(“enter the n value”);
n=in.nextInt();
int a[][]=new int[n][n];

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

}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+” “);
}
System.out.println();

}

System.out.println(“sub martix”);

for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{

System.out.print(a[i][j]+” “);
if(a[i][j]==0)
{
c1++;
}
k1++;

}

}

System.out.println(“\ncheck rev sub martix”);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{

System.out.print(a[j][i]+” “);
if(a[j][i]==0)
{
c2++;
}
k2++;
}

}
for(i=0;i<n;i++)
{
if(a[i][i]==0)
{
d++;
}

}
if((c1==c2)&&(d!=n))
{
System.out.println(“D”);
}
else if((c1==c2)&&(d==n))
{
System.out.println(“N”);
}
else if(c2==k2)

{
System.out.println(“U”);
}
else if(c1==k1)
{
System.out.println(“L”);
}

}

}