0

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.
Thanks in advance :icon_cry:

3
Contributors
5
Replies
15
Views
7 Years
Discussion Span
Last Post by rkj2ban
0

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

0

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.

Edited by JamesCherrill: n/a

0

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;
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String: ");
String s=b.readLine();
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();
}
}

Edited by jammy4java: n/a

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.