Social Icons

Saturday, 21 September 2013

Sum Of all cross diagonals of an array

import java.util.Scanner;
class Array
{
public static void main(String args[])
{int l,k;
int count=0,sum=0;
 int a[][]=new int[4][4];
 int i,j,c;
Scanner s= new Scanner(System.in);

System.out.println("Enter element Of the array : ");
for(i=0;i<a.length;i++)
{
for(j=0;j<a[i].length;j++)
{
a[i][j]=s.nextInt();
}

}

System.out.println(" Element Of the array are : ");
for(i=0;i<a.length;i++)
{
for(j=0;j<a[i].length;j++)
{
System.out.print(" "+a[i][j]);
}
System.out.println("");

}

l=a.length-2;

System.out.println("Sum of the Diagonals Element Of the array are : ");
System.out.println("element at the  left    corner is  : "+a[a.length-1][0]);
for(c=l;c>=0;c--)
{
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{

   if(i==(j+c))
   {  
   count=count+a[i][j];
    }
 
 }
 }

 System.out.println("Sum of diagonal starting at row "+"is:"+count);



count=0;

}


for(c=1;c<a.length-1;c++)
{
for(i=0;i<a.length;i++)
{
for(j=0;j<a.length;j++)
{

   if(i+c==j)
   {  
   count=count+a[i][j];
    }
 
 }
 }

 System.out.println(" Sum of diagonal starting at row "+"is :  "+count);



count=0;

}


System.out.println(" element  at  the   right corner is: "+a[0][a.length-1]);

}
}

world replacement in String program in java

class Com_pare
{

public static void main(String args[])
{

int i=0,m,t,n,o,c=0;
String search="six";
String s1="welcomlce to jalcva";
String s2="six pack is alwas six in the interval of six";
String p;
String x;

char a[]=s2.toCharArray();
for(i=0;i<a.length;i++)
{
 if(a[i]=='s' && a[i+1]=='i' && a[i+2]=='x')
{
 
c=c+1;
}
}



for(t=0;t<c;t++)
{
m=s2.indexOf("six");
s2=s2.substring(0,m)+"was"+s2.substring(m+search.length(),s2.length());
}


System.out.println(" String After replacement "+s2);
System.out.println(" no. of timelc occurs  "+c);


}



}

Monday, 16 September 2013

insertion sort in java


import java.util.Scanner;
class insert
{
  public static void main(String args[])
  {
  Scanner s = new Scanner(System.in);
  int i,b,c,temp;
  int j;
  int a[] = new int[5];
  System.out.println("\n Enter Element into the array: ");
  for(i=0;i<5;i++)
  {
   a[i]=s.nextInt();
  }
  System.out.println("\n The Element into the array are : ");
  for(i=0;i<5;i++)
  {
   System.out.print(a[i]+" ");
  }




   for(i=0;i<5;i++)
   {
    temp=a[i];
j=i-1;
   while(j>=0 && temp<a[j])
    {
      a[j+1]=a[j];

 j=j-1;
}
 a[j+1]=temp;

 
  }

    System.out.println("\n The Element after sorting into the array are : ");
  for(i=0;i<5;i++)
  {
   System.out.print(a[i]+" ");
  }





 }

}

Friday, 6 September 2013

Anonymous array


class Arr
{
static int i=5;

 static void F(int p[])
  {
  for(i=0;i<p.length;i++)
  {
  System.out.print(p[i]+" ");
 
   }
   }



 public static void main(String args[])
 {
  Arr a= new Arr();
   int i,j;

   F(new int[] {1,2,3,4});
 


  }

}
 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management