USING JAVA First, write a Java method isSequence that takes as parameters a non-empty 2-dimensional array of integers. The method checks whether the elements of the array are consecutive or not. Second, write a java methods printArray(int[][]a) that writes the elements of an array passed in parameter to the standard output. Finally, use the following main method to test your different methods: public class CheckSequence { public static void main(String[] args) { int[][] array1 = {{5,6,7,8},{9,10,11,12},{13,14,15,16}, {17,18,19,20}}; int[][] array2 = {{1, 3 , 2,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; if (isSequence(array1)) { System.out.println("The following array elements are successive:"); printArray(array1); } if (isSequence(array2)) { System.out.println("The following array elements are successive:"); printArray(array2); } } } Run Example: The following array elements are successive: 5678 9 10 11 12 13 14 15 16 17 18 19 20
USING JAVA
First, write a Java method isSequence that takes as parameters a non-empty 2-dimensional
array of integers. The method checks whether the elements of the array are consecutive or not.
Second, write a java methods printArray(int[][]a) that writes the elements of an array passed in parameter to the standard output.
Finally, use the following main method to test your different methods:
public class CheckSequence { public static void main(String[] args) {int[][] array1 = {{5,6,7,8},{9,10,11,12},{13,14,15,16}, {17,18,19,20}}; int[][] array2 = {{1, 3 , 2,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
if (isSequence(array1)) {System.out.println("The following array elements are successive:");
printArray(array1); } if (isSequence(array2)) {System.out.println("The following array elements are successive:");
} }
Run Example:
The following array elements are successive: 5678
9 10 11 12
13 14 15 16
17 18 19 20
Step by step
Solved in 3 steps with 2 images