Need some help regarding this program.
I had done a similar program having output as:-

S A I F E E
S A I F E
S A I F
S A I
S A
S

Its output is as follows:-

``````class Name
{
public static void main(String args[])
{
String s="SAIFEE";
int num=s.length();
while(num>0)
{
for(int j=0;j<num;j++)
{
System.out.print(" "+s.charAt(j)+" ");
}
System.out.println();
num--;
}
}
}``````

But I'm unable to find a logic to develop a code for this program:-
Input: Tiger
Output:-

Tigeregit
igeregi
gereg
ere
r
ere
gereg
igeregi
Tigeregit

I'll be obliged if anyone helps me out on this.

## All 5 Replies

Err... gaps have vanished, its shape will be like that of a 45 degree triangle.
The pattern will form an X shape and not K as shown above

for i = 0 to (length of string+!)/2
print string with first and last i characters replaced with blanks.
repeat loop with starting and ending values of i swapped.

I've got the basic code, just need to work on the gaps now.
This one is forming a K shape instead of X shape

Here's the code:-

``````import java.io.*;
class StringArray
{
public static void main(String args[])throws IOException
{
int i,j,n,spaces;
System.out.print("Enter a String: ");
n=s.length();
for(i=n;i>0;i--)
{
System.out.println();
if(i==1)
break;
for(j=n-i;j<n;j++)
System.out.print(s.charAt(j));
for(j=n-2;j>n-i-1;j--)
System.out.print(s.charAt(j));
}
System.out.print(s.charAt(n-i));
for(i=1;i<n;i++)
{
System.out.println();
for(j=n-i-1;j<n;j++)
System.out.print(s.charAt(j));
for(j=n-2;j>=n-i-1;j--)
System.out.print(s.charAt(j));
}
System.out.println();
}
}``````

Need some help regarding this program.
I NEED a similar program for odd number words having output as:-

I
N
I N D I A
I
A

Need some help regarding this program.
I NEED a similar program for odd number words in + format
D as mean, horizontal & verticle, having output as:-

I
N
I N D I A
I
A

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.