I need some help finishing my program. This is what i have so far and below what
ID: 644080 • Letter: I
Question
I need some help finishing my program. This is what i have so far and below what i have is what it has to be.
public static void main(String[] args) {
int [] list = {-3};
int [] list2 = {-1};
int [] list3 = {5};
int [] list4 = {10};
int [] list5 = {3};
int [] list6 = {17};
int [] list7 = {2};
for (int i = 0; i < list.length; i++) {
System.out.println("[" + "0:" + list[i] + ", " + "1:" + list2[i] + ", " +
"2:" + list3[i] + ", " + "3:" + list4[i] + ", " + "4:" +
list5[i] + ", " + "5:" + list6[i] + ", " + "6:" + list7[i] + "]");
}
}
public static int findMaxNum () {
return -1;
}
public static int findMaxArrayIndex () {
return -1;
}
public static int deleteNumFromArray () {
return -1;
}
}
Creates an integer array with the following values in the following order: -3, -1, 5, 10, 3, 17, 2. Note: Your TA may change these values for your lab section.
[2 pts] Create a method that takes an integer array as an argument and outputs the array values to the console with the following formatting. The output should begin with a
Explanation / Answer
public class MaxInteger {
public static void main(String[] args) {
int[] myArray = { -3, -1, 5, 10, 3, 17, 2 };
maxIndex(myArray);
}
public static void maxIndex(int myArray[]) {
if (myArray.length < 1) {
System.out.println("[]");
return;
}
int[] newArray = new int[myArray.length - 1];
int maxIndex = getIndexFormat(myArray);
for (int i = 0, j = 0; i < myArray.length; i++, j++) {
if (i != maxIndex) {
newArray[j] = myArray[i] - 1;
} else {
j--;
}
}
getIndexFormat(newArray);
}
public static int getIndexFormat(int myArray[]) {
int max = myArray[0];
int index = 0;
System.out.print("[");
for (int i = 0; i < myArray.length; i++) {
if (myArray[i] > max) {
max = myArray[i];
index = i;
}
System.out.print(i + ":" + myArray[i] + ", ");
}
System.out.println("]");
System.out.println("Maximum value " + max + " found at index " + index);
return index;
}
}