The code below:
package javaFullcourse;
import java.util.Scanner;
public class TwoD {
public static void main(String[] args) {
System.out.println("Enter array elements:");
Scanner s=new Scanner(System.in);
int rows=s.nextInt();
int cols=s.nextInt();
int numbers[][]=new int[rows][cols];
for(int i=0;i<rows;i++) {
for(int j=0;j<rows;j++) {
numbers[i][j]=s.nextInt();
}
}
int x=s.nextInt();
for(int i=0;i<rows;i++) {
for(int j=0;j<rows;j++) {
if(numbers[i][j]==x) {
System.out.print("x is found at location("+i+","+j+")");
}
}
}
}
}
It automatically posts the indices without the user's input of the given number. Why?? What I am doing wrong? Please help.