Home / Blue J / Program for string in cross x format on given position

Program for string in cross x format on given position

Program for string in x format on given contact position in the middle of your output screen 

class formatx
{
public static void main(String s,int n)
{
int i,j,k,l=s.length();
char a[][]=new char[l*l][l*l];
j=l/2;
for(i=0;i<15-j;i++)
System.out.println();
for(i=0;i<l;i++)< span="">
a[i][l+i]=s.charAt(i);

j=l+n;
k=n-2;
for(i=n-2;i>-1;i--)
a[i][j++]=s.charAt(k--);
j=l+n-2;
k=n;
for(i=n;i<l;i++)< span="">
a[i][j--]=s.charAt(k++);
for(i=0;i<l;i++)< span="">
{
for(j=0;j<65-l-n;j++)
System.out.print(' ');
for(j=0;j<l*3;j++)< span="">
{
if(a[i][j]!=0)
System.out.print(a[i][j]);
else
System.out.print(' ');
}
System.out.println();
}
}
}

Input:   “program” , 4

Output :


tags: java program for string in x format, program for string in x format at ith position.

Check Also

Program to check Upper Triangular matrix

What is Upper Triangular Matrix?  An upper triangular matrix is a square matrix in which ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.