There is a method called initializeKeyPad()
that takes in a 2D array and will initialize the 2D array to represent a numerical keypad:
1 2 3 4 5 6 7 8 9 0
The method will also print the numeric pad upside-down, like this:
0 7 8 9 4 5 6 1 2 3
There is another method called reverseArray()
that generates an integer array containing the numbers from 1 to 10 in descending order. Print the array twice as initialized and reversed, like this:
10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10
There is final method called intializeRandomList()
that takes in the parameters n (integer), asciiStart (integer), and x (integer). The method should generate n random integers between 0 and 32 and add them to the asciiStart character to obtain random characters. These characters should be added to an ArrayList and returned.
Write the methods initializeKeyPad(int[][] arr)
, reverseArray()
, and initializeRandomList()
.
public class Methods {
public static void initializeKeyPad(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
arr[i][j] = i * 3 + j + 1;
}
}
arr[arr.length - 1][arr[0].length - 1] = 0;
for (int i = arr.length - 2; i >= 0; i--) {
for (int j = arr[0].length - 1; j >= 0; j--) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
arr[arr.length - 1][0] = 0;
}
}
public static int[] reverseArray() {
int[] arr = new int[10];
for (int i = 0; i < arr.length; i++) {
arr[i] = i + 1;
}
for (int i = 0; i < arr.length / 2; i++) {
int temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
return arr;
}
public static ArrayList<Character> initializeRandomList(int n, int asciiStart, int x) {
ArrayList<Character> randomList = new ArrayList<>();
Random randomGenerator = new Random(x);
for (int i = 0; i < n; i++) {
randomList.add((char) (randomGenerator.nextInt(33) + asciiStart));
}
return randomList;
}
int[][] arr = new int[4][3];
Methods.initializeKeyPad(arr);
int[] reversedArray = Methods.reverseArray();
ArrayList<Character> randomList = Methods.initializeRandomList(10, 65, 12345);
9 8 7
6 5 4
3 2 1
| int[] reversedArray = Methods.reverseArray();
cannot find symbol
symbol: method reverseArray()