public class ArrayIntList {
private int[] elementData;
private int size;
// Constructor to initialize the array and size
public ArrayIntList(int[] input) {
this.elementData = input;
this.size = input.length;
}
// Sum method as described
public int sum() {
int output = 0;
for (int i = 0; i < this.size; i++) {
output += this.elementData[i];
}
return output;
}
// Main method to test our ArrayIntList class
public static void main(String[] args) {
int[] testData = {1, 2, 3, 4, 5};
ArrayIntList list = new ArrayIntList(testData);
System.out.println("Sum of integers in the ArrayIntList: " + list.sum()); // Expected output: 15
}
}
javaCopy code
public class StringManipulator {
// Constructor
public StringManipulator() {
}
// Returns the reversed version of the input string.
public String reverse(String input) {
// Ensure input is not null
if (input == null) {
return null;
}