+ 3
How can I make my Pascal Triangle centrally aligned in Java???
i made a pascal triangle. but it 's shape is not like a pyramid, centrally aligned it goes like.. 1 1 1 1 2 1.. while it should be like... 1 1 1 1 2 1 PLZ SOMEBODY HELP ME WITH IT. HERE'S MY CODE--- https://code.sololearn.com/cf3o8bUdK50w/?ref=app
2 Answers
+ 2
else{
System.out.println("Here's your Pascal Triangle for "+n+ " rows");
//NEW
long spaces = n;
spaces--;
for(long i=spaces; i>0; i--){
System.out.print(" ");
}
//END
System.out.println("1");
for(x=1;x<n;x++)
{
y=(long)Math.pow(11,x);
// NEW
spaces--;
for(long i=spaces; i>0; i--){
System.out.print(" ");
}
//END
while(y!=0){
c=y%10;
System.out.print(c+" ");
y=y/10;
}
System.out.println();
}
// this is the else statement i changed (the forloop with the space variable)
+ 2
thnks man, i got it :)