0% found this document useful (0 votes)
3 views2 pages

Java 2D Array Input and Search

The Java program allows users to input dimensions for a 2D array and populate it with integers. It then displays the array and prompts the user to enter a number to find its index within the array. If the number is found, its indices are printed; otherwise, a message indicates that the number is not found.

Uploaded by

filmtwotwo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java 2D Array Input and Search

The Java program allows users to input dimensions for a 2D array and populate it with integers. It then displays the array and prompts the user to enter a number to find its index within the array. If the number is found, its indices are printed; otherwise, a message indicates that the number is not found.

Uploaded by

filmtwotwo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;

public class arraynum {

public static void main(String args[]){

Scanner sc= new Scanner([Link]);


int row= [Link]();
int col= [Link]();
int numbers[][]= new int[row][col];

[Link]("enter data in your 2D array: ");


for(int i= 0; i<row; i++){
for(int j=0; j<col; j++){
numbers[i][j]= [Link]();
}
}

[Link]("here is your 2D array: ");


for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
[Link](numbers[i][j] + " ");
}
[Link]("\n");
}

[Link]("enter the number you to find index of:");


int guessnum= [Link]();
int r = 0;
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
if(numbers[i][j] == guessnum){
[Link]("index for the " + guessnum + " is: " +
i+ " " + j );
r++;
}

}
}

if(r == 0){
[Link]("num is not found in an array");
}

}
}

You might also like