0
    import java.util.Scanner;
    import java.io.*;
    import java.lang.*;

  public class triangle
 {
  public static void main(String []args)
  {
      System.out.println("enter no. of test cases!!");
    Scanner sc = new Scanner(System.in);

  int i,j,k,n,m,sum=0;


 m=sc.nextInt();

while(m>0)
{
System.out.println("enter the no. of lines!");
n=sc.nextInt();
int a[n][n] ;


 for(i=0;i<n;i++)
 {
  for(j=0;j<i;j++)
   {
   a[i][j]=sc.nextInt();
    } 

   }



 sum= a[0][0];

for(i=0;i<n;i++)
 {
 k=0;
   for(j=0;j<i;j++)
   {

 if(a[i][k]>a[i][k+1])
 {
 sum= sum + a[i][k];
 }
 else
 {
 sum=sum+ a[i][k+1];
 k++;
 }
 }
 }
 System.out.println("sum is :"+sum);

 m--;
}
}
}

I have tried it for hours but could not get it, the errors are going above my head, help me out. these following are errors:- Main.java:17: error: ']' expected int a[n][n]; ^ Main.java:17: error: illegal start of expression int a[n][n]; ^ Main.java:17: error: ';' expected int a[n][n]; ^ Main.java:17: error: not a statement int a[n][n]; ^ Main.java:17: error: ';' expected int a[n][n]; ^

karan_13
  • 23
  • 5

1 Answers1

1

int a[n][n]; is not a valid array declaration.

It should be :

int[][] a = new int[n][n];
Eran
  • 359,724
  • 45
  • 626
  • 694