For example, a given user input array is {{1,2,3},{4,5,6}} and the user input integer value is 6. If 6 is in the array, I want to print its index (for example [1][2]). I was able to write the code that will scan the given elements of the array however, I'm not sure what to do next in order to find the given integer value in the array.
Here's my code:
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
int toFind;
System.out.print("Enter the number of rows: ");
int row =scan.nextInt();
System.out.print("Enter the number of columns: ");
int column =scan.nextInt();
int input[][] = new int[row][column];
System.out.println("Elements: ");
for(int ctr1 = 0; ctr1 < input.length; ctr1++)
{
for(int ctr2 = 0; ctr2 < input[ctr1].length; ctr2++)
{
input[ctr1][ctr2] = scan.nextInt();
}
}
System.out.println("Enter the number you want to find: ");
toFind = scan.nextInt();
I'm not sure what to next here in order to initiate the checking of the number in the given array and print its index.