Input Format:
The first line has an integer . In each of the next lines there will be an integer denoting number of integers on that line and then there will be space-separated integers. In the next line there will be an integer denoting number of queries. Each query will consist of two integers x and y.
Output Format:
In each line, output the number located in yth position of xth line. If there is no such position, just print "ERROR!"
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt();
Integer arr[][] = new Integer[x][];
arr[x][100] = null;
for(int i=0;i < x;i++){
int y = in.nextInt();
for(int j = 0;j<y;j++){
arr[i][j] = in.nextInt();
}
}
int z = in.nextInt();
for(int k=0;k<z;k++){
int p = in.nextInt();
int q = in.nextInt();
if(arr[p-1][q-1] == null){
System.out.printf("%s\n","ERROR!");
}
else
System.out.printf("%d\n",arr[p-1][q-1]);
}
}
When I run this I'm getting error as
Solution.java:23: error: incomparable types: int and <null>
if(arr[p-1][q-1] == null){
How do I avoid this error in future?
Integerarray instead of anintarray and initialize it's elements withnull.