I have a problem with printing the spaces at the begining of each line in the following shape
but the code i developed print it like that
1
121
12321
1234321
12321
121
1
and this is the code i developed
I wanna know how i print the spaces at the begining of each line
here you will enter the wanted input number ,variable centeredNumber, as 4
to print the shape i put it
1
121
12321
1234321
12321
121
1
121
12321
1234321
12321
121
1
but the code i developed print it like that
1
121
12321
1234321
12321
121
1
and this is the code i developed
Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final int N=1;
System.out.println( "Enter the centered number " );
Scanner input =new Scanner(System.in);
int centeredNumber;
centeredNumber=input.nextInt();
for(int x=0;x<centeredNumber;x++)
{
String p="";
for(int k=1 ;k<N+x;k++)
p+=k;
StringBuffer str = new StringBuffer(p);
System.out.print(str);
System.out.print(N+x);
str.reverse();
System.out.println(str);
if(x==centeredNumber-1)
{
for(int xx=x-1;xx>=0;xx--)
{
String pp="";
for(int k=1 ;k<N+xx;k++)
pp+=k;
StringBuffer str1 = new StringBuffer(pp);
System.out.print(str1);
System.out.print(N+xx);
str1.reverse();
System.out.println(str1);
}
}
}
}
}
here you will enter the wanted input number ,variable centeredNumber, as 4
to print the shape i put it
Comment