Question: Please write comments on this program explaining what each method array and sentinel does/is. Thank you. import java.util.Scanner; public class Lab12 { public static void
Please write comments on this program explaining what each method array and sentinel does/is. Thank you.
import java.util.Scanner;
public class Lab12
{
public static void main(String[] args) {
final int pSize = 10;
int[] sized = { -51, -1, 5, 21, 36, 58, 64, 128, 256, 512};
int[] sent = { 1, 3, 5, 7, 11, 13, 17, 0, 6, 8 };
System.out.print(" The sized array: ");
printSizedArray(sized, pSize);
System.out.print(" The same sized array reversed: ");
revArray(sized, pSize);
printSizedArray(sized, pSize);
System.out.print(" The sentinel terminated array: ");
printSentArray(sent, 0);
System.out.print(" The same sentinel terminated array doubled: ");
doubArray(sent);
printSentArray(sent, 0);
System.out.println("");
}
public static void printSizedArray(int[] arr, final int eSize) {
for (int i = 0; i < eSize; ++i)
System.out.print(arr[i] + " ");
System.out.println("");
}
public static void printSentArray(int[] arr, int sentVal) {
for (int i = 0; arr[i] != sentVal; ++i)
System.out.print(arr[i] + " ");
System.out.println("");
}
public static void revArray(int[] arr, final int eSize) {
for (int i = 0, j = eSize - 1; i <= eSize / 2; ++i, --j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
public static void doubArray(int[] arr) {
for (int i = 0; arr[i] != 0; i++)
arr[i] = 2 * arr[i];
}
}
Step by Step Solution
There are 3 Steps involved in it
Lets break down the program step by step and explain each part Overview of the Program This Java program manipulates two arrays using various methods ... View full answer
Get step-by-step solutions from verified subject matter experts
