Emergency Pop Quiz
public class Keypad{
public static void initializeKeypad() {
int[][] keypad = new int[4][3];
int digit = 1;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 3; col++) {
if (digit <= 9) {
keypad[row][col] = digit++;
} else {
keypad[row][col] = 0; // For digit 0
}
}
}
// Print the keypad
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 3; col++) {
System.out.print(keypad[row][col] + " ");
}
System.out.println(); // Move to the next row
}
}
public static void main(String[] args) {
initializeKeypad();
}
}
Keypad.main(null)
import java.util.*;
public class Main {
public static ArrayList<Integer> initializeRandomList(Integer n, Integer min, Integer max) {
ArrayList<Integer> randList = new ArrayList<>();
for (int i = 0; i < n; i++) {
int randomNum = (int) (Math.random() * (max - min + 1)) + min;
randList.add(randomNum); // Use .add() to add elements to ArrayList
}
return randList;
}
public static void main(String[] args) {
ArrayList<Integer> randomList = initializeRandomList(5, 2, 8);
System.out.println(randomList);
}
}
Main.main(null)
import java.util.*;
public class Main {
public static ArrayList<Integer> reversedArray(ArrayList<Integer> n) {
ArrayList<Integer> reverse = new ArrayList<>();
for (int i = n.size() - 1; i >= 0; i--) {
reverse.add(n.get(i));
}
return reverse;
}
public static void main(String[] args) {
ArrayList<Integer> originalList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
ArrayList<Integer> reversedList = reversedArray(originalList);
System.out.println("Original List:");
System.out.println(originalList);
System.out.println("Reversed List:");
System.out.println(reversedList);
}
}
Main.main(null)
Original List:
[1, 2, 3, 4, 5]
Reversed List:
[5, 4, 3, 2, 1]