Question
+ Find the summation of all integers in the array.
+ Find the average, the maximum and minimum numbers of the array.
+ Double numbers in the 1st position, the 3rd position, the 6th, 9th, 12th, etc in the array.
+ Sort the array using bubble sort
+ Sort the array using selection sort
+ Ask the user for a key. Search for that key in the sorted array using sequential search
+ Ask the user for a key. Search for that key in the sorted array using binary search
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.util.Arrays;public class ArrayManip {
public final static int N = 100;
public final static int Low = 20;
public final static int Up = 1000;
public static void main(String[] args)
{
int[] arrInt = new int[N], arrCopy = new int[N];
for(int i = 0; i < N; i++)
{
arrInt[i] = (int)(Math.random() * (Up+1-Low) + Low);
System.out.print(arrInt[i] + " ");
}
System.arraycopy(arrInt, 0, arrCopy, 0, arrInt.length);
System.out.println("\nSum: " + arraySum(arrInt));
System.out.println("Average: " + arrayAvg(arrInt));
int[] newArr = doubleArrayPos(arrCopy);
for(int i = 0; i < N; i++)
{
System.out.print(newArr[i] + " ");
}
System.out.println();
System.arraycopy(arrInt, 0, arrCopy, 0, arrInt.length);
newArr = bubbleSort(arrCopy);
for(int i = 0; i < N; i++)
{
System.out.print(newArr[i] + " ");
}
System.out.println();
System.arraycopy(arrInt, 0, arrCopy, 0, arrInt.length);
newArr = selectionSort(arrCopy);
for(int i = 0; i < N; i++)
{
System.out.print(newArr[i] + " ");
}
System.out.println();
System.out.println("Index for key 20 (sequential): " + sequentialSearch(20, newArr));
System.out.println("Index for key 20 (binary): " + binarySearch(20, newArr));
}...