0

I am getting compile time error for this code. Not getting what it is about, please help. This is some practice question on codechef.

Tried to find on web but unable to find similar answers.

The code is-

import java.util.*;

class missp 
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int i,j,n,c=0;
int a[];

while(t>0)
{
c=0;
n =sc.nextInt();
a[]=new int[n];

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

for(i=0;i<n;i++)
{  
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
c++;
break;
}
}
if(c=0)
System.out.println(a[i]);
break;
}
t--;
}
} 
}//end of class

the errors are-

  Main.java:16: error: not a statement
 a[]=new int[n];
  ^
 Main.java:16: error: ';' expected
 a[]=new int[n];
    ^
 Main.java:16: error: ']' expected
 a[]=new int[n];
             ^
 Main.java:16: error: ';' expected
 a[]=new int[n];
              ^
4 errors
karan_13
  • 23
  • 5

1 Answers1

2

Remove the brackets from a[]=new int[n];

You don't need to include the brackets when initializing because the variable name is "a", not "a[]".

Andrew Fan
  • 1,313
  • 5
  • 17
  • 29
CConard96
  • 874
  • 1
  • 7
  • 18