// This file contains several sample problems discussed in lecture. This // file contains the problem specifications in case you want to work on them // on your own. import java.util.*; public class ArraySample3 { public static void main(String[] args) { int[] list1 = {12, 8, 4, 0, 208, 14, 42, 38, 72, 96, 102}; int[] list2 = {84, 42, 92, 96, 2, 4, 8, 0, 72, 302, 17, 2, 408}; System.out.println("list1 = " + Arrays.toString(list1)); System.out.println("list2 = " + Arrays.toString(list2)); // System.out.println("indexOf(list1, 42) returns " + indexOf(list1, 42)); // System.out.println("indexOf(list1, 16) returns " + indexOf(list1, 16)); // System.out.println("indexOf(list2, 42) returns " + indexOf(list2, 42)); // System.out.println("indexOf(list2, 16) returns " + indexOf(list2, 16)); // System.out.println("isUnique(list1) returns " + isUnique(list1)); // System.out.println("isUnique(list2) returns " + isUnique(list2)); // int[] sum = runningSum(list1); // System.out.println("runningSum(list1) = " + Arrays.toString(sum)); // sum = runningSum(list2); // System.out.println("runningSum(list2) = " + Arrays.toString(sum)); // System.out.println("result of rotating left:"); // System.out.println(" list1 = " + Arrays.toString(list1)); // for (int i = 0; i < list1.length; i++) { // rotateLeft(list1); // System.out.println(" list1 = " + Arrays.toString(list1)); // } // System.out.println("result of rotating right:"); // System.out.println(" list2 = " + Arrays.toString(list2)); // for (int i = 0; i < list2.length; i++) { // rotateRight(list2); // System.out.println(" list2 = " + Arrays.toString(list2)); // } } // Write a static method called indexOf that takes an array of integers and // a value as parameters and that returns the index of the first occurrence // of the value in the array, returning -1 if not found // Write a static method called isUnique that takes an array of integers as // a parameter and that returns true if the values in the list are unique // and that returns false otherwise. The values in the list are considered // unique if there is no pair of values that are equal. // Write a static method called runningSum that takes an array of integers // as a parameter and that returns a new array that contains the running // sum of the numbers in the array (where the i-th value of the new array // is the sum of the first i values of the original array) // Write a static method called rotateLeft that takes a nonempty array of // integers as a parameter and that rotates all values to the left by one // position, rotating the first value to the back of the array. For // example, given the list {1, 2, 3, 4}, a call on rotateLeft should yield // {2, 3, 4, 1}. // Write a static method called rotateRight that takes a nonempty array of // integers as a parameter and that rotates all values to the right by one // position, rotating the last value to the front of the array (e.g., given // the list {1, 2, 3, 4}, a call on rotateRight should yield the list {4, // 1, 2, 3}) }