You are on page 1of 5

public class Zohotest1

{
public static void main(String[] aa)
{
String a;
a="a1b2c3d4e51";
StringBuilder b = new StringBuilder("");
b.append(a);

int x=a.length()/2+a.length()%2;
System.out.println(x);
int y=0;
for(int i=0;i<a.length();i++)
{

if (i%2==1) {b.setCharAt(x++,a.charAt(i));}
else b.setCharAt(y++,a.charAt(i));

}
System.out.println(b);
}
}

OUTPUT:

$javac Zohotest1.java
$java -Xmx128M -Xms16M Zohotest1
6
abcde112345

public class matrix2{


public static void main(String []args){
int[][] a={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
int n=4;
int temp;
int col=n-1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println(" ");
}
System.out.println(" ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
{
temp=a[i][j];
a[i][j]=a[i][col];
a[i][col]=temp;
col--;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println(" ");
}
}
}
OUTPUT:

$javac matrix2.java
$java -Xmx128M -Xms16M matrix2

1234
5678
9 10 11 12
13 14 15 16

4231
5768
9 11 10 12
16 14 15 13
public class pattern{
public static void main(String []args){
int [][] a = new int[50][50];
int n=5;
int row=0;
int col=2*n;
int m=n;
for(int i=0;i<2*n;i++)
{
for(int j=0;j<2*n;j++)
{
a[i][j]=n;
}
}
System.out.println("PATTERN ");
for(int i=0;i<(2*n)-1;i++)
{
for(int j=i;j<col-1;j++)
{
a[row][j]=m;
a[j][row]=m;
a[j][col-2]=m;
a[col-2][j]=m;
}
row++;
col--;
m--;
}
System.out.println(" ");
for(int i=0;i<2*n-1;i++)
{
for(int j=0;j<2*n-1;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println(" ");
}
System.out.println(" ");

}}
OUTPUT:
$javac pattern.java
$java -Xmx128M -Xms16M pattern
PATTERN
555555555
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555
Python Coding:
n=5
for i in range(n):

for j in range(i):
print(n-j," ",end="")
for j in range(i,n*2-i):
print(n-i," ",end="")

for j in range(i):
print(n-i+j+1," ",end="")
print()
for i in range(n-1,-1,-1):

for j in range(i):
print(n-j," ",end="")
for j in range(i,n*2-i):
print(n-i," ",end="")

for j in range(i):
print(n-i+j+1," ",end="")
print()
#python 3.6

#python 2.7.6

n=5

for i in range(n-1):
for j in range(i):
print(n-j," ",end="")
for j in range(i+1,n*2-i):
print(n-i," ",end="")

for j in range(i):
print(n-i+j+1," ",end="")
print()

for i in range(n-1,-1,-1):

for j in range(i):
print(n-j," ",end="")
for j in range(i+1,n*2-i):
print(n-i," ",end="")
for j in range(i):
print(n-i+j+1," ",end="")
print()