0
while(i>=j);
                System.out.println("-----------------------");
                       System.out.print("[");
                        for(int x=0; x<=n+r; x++){
                         System.out.print ((arrPascal[n+r][x])+",");
                }
                System.out.print("]");
        }

My code prints

[1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, ]

I want to print

[1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1]

Tried print statement:

System.out.print (Arrays.toString(arrPascal[n+r][x]))

Results in error:

The method toString(long[]) in the type Arrays is not applicable for the arguments (long)
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

This can be a solution it ignores to print the "," if its the last element. Hope it would help.

while(i>=j);
            System.out.println("-----------------------");
                   System.out.print("[");
                    for(int x=0; x<=n+r; x++){
                    
                     System.out.print ((arrPascal[n+r][x]));
                     if(x<n+r){
                     System.out.print(",");

                     }
            }
            System.out.print("]");
    }

Edit 1: Rather than the above approach you should go for:

int arrPascal[] = {1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1};  
System.out.println(Arrays.toString(arrPascal));

Output

[1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1]  

If you have to print a nested array.

System.out.println(Arrays.deepToString(arrPascal));  
satvik
  • 95
  • 9