I want to make a program to accept strings and make a pyramid of strings, but I cant make the right loop, I have the logic:
But this seems to make only half- pyramid, can somebody help me with the right loop
import java.util.Scanner;
public class Stairs
{
public void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
String a = sc.nextLine();
int x, y;
for (x = 0; x < a.length(); x++)
{
for (y = 0; y <= x; y++)
{
char c = a.charAt(y);
System.out.print(c);
}
System.out.println();
}
}
}
for (y = 0; y <= x; y++)
{
char c = a.charAt(y);
System.out.print(c);
}
System.out.println();
}