+ 2

How to print this in java using nested loops?

1 11 121 1331 14641

20th Apr 2018, 6:31 AM
Thor King
Thor King - avatar
3 Antworten
+ 12
import java.util.*; public class Program { public static void main(String[] args) { int rows,coef = 1; rows= new Scanner(System.in).nextInt(); for(int i=0; i<rows; i++) { for(int space=0; space < rows-i; space++) System.out.print(" "); for(int j=0; j <= i; j++) { if (j==0 || i==0) coef = 1; else coef = coef*(i-j+1)/j; System.out.print(" "+coef); } System.out.println();}}}
20th Apr 2018, 7:45 AM
Mert Yazıcı
Mert Yazıcı - avatar
+ 1
there are several pascal triangle codes you can refer to here https://code.sololearn.com/cf3o8bUdK50w/?ref=app
20th Apr 2018, 7:54 AM
᠌᠌Code X
᠌᠌Code X - avatar
- 1
Why the specific nested loops requirement? Why is this code not enough: System.out.println ("1 \n 11 \n 121 \n 1331 \n 14641");
20th Apr 2018, 6:50 AM
***
*** - avatar