Answered step by step
Verified Expert Solution
Question
1 Approved Answer
undefined In this last problem, you will implement a method to print a cell's neighbours on a 2D array. The method's header (documented with java
undefined
In this last problem, you will implement a method to print a cell's neighbours on a 2D array. The method's header (documented with java docs) is provided. The main method (do not alter it) will read N numbers to create the 2D array, and it will call your method for you. Be careful not to go out of the bounds of the 2D array! Example (see the output of a test case for the complete output) The method should print the neighbours of 11 in the following order: 6 7 8 10 12 14 15 16 L- 1 2 3 4 6 7 8 19 10 11 12 14 15 16 10 Problem 3.java New 1. import java.util.Arrays; 2 import java.util.Scanner; 3 4. public class Problem3 { 5 6 /** 7 * Method used to print all the neighbours of an element inside a 2D array. 8 * The method will print each neighbour in a new line as {row, col}: value 9 @param data the 2D array @param row the row coordinate of the centre (point we want to print the neighbours) 11 * @param col the col coordinate of the centre (point we want to print the neighbours) 12 13- public static void printNeighbours (int[][] data, int row, int col) { 14 15 } 16 17 - /** 18 * DO NOT ALTER ME! 19 * @param args NOPE! 20 21 - public static void main(String[] args) { 22 Scanner kb = new Scanner(System.in); 23 int[][] data = new int[kb.nextInt()][kb.nextInt()]; 24 25- for (int i = 0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started