+ 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

15th Oct 2017, 4:55 PM
Aaron Stone
Aaron Stone - avatar
2 Réponses
+ 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)
17th Oct 2017, 12:58 AM
Chrizzhigh
Chrizzhigh - avatar
+ 2
thnks man, i got it :)
17th Oct 2017, 9:06 AM
Aaron Stone
Aaron Stone - avatar