Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int target = scan.nextInt();
- int[][] arr = {
- {2, 3, 4},
- {5, 3, 7},
- {8, 3, 3},
- };
- boolean found= false;
- for (int row = 0; row < arr.length; row++) {
- for (int col = 0; col < arr[0].length; col++) {
- if (target == arr[row][col] && found == true){
- System.out.printf(", [%d][%d]",row,col);
- }
- if (target == arr[row][col] && found == false) {
- System.out.printf("Index is: [%d][%d]",row, col);
- found = true;
- }
- }
- }
- if (found == false){
- System.out.println("Not found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement