Question: Can someone please help me debug this? I cannot get my results past my last integer or #3 to print out correctly. I will rate
Can someone please help me debug this? I cannot get my results past my "last integer" or #3 to print out correctly. I will rate for good/correct solutions and decent explanation of what I am not doing correctly. Thank you in advance!
import java.util.*;
public class Assignment06 {
public static void main(String[] args) {
int[] myArray = {1, 22, 333, 400, 5005, 9}; System.out.print("Your array: "); printArray(myArray, ", "); System.out.println(""); System.out.print("Your array: "); printArray(myArray, " - "); System.out.println(""); System.out.print("The first integer in the array is: "); System.out.print(getFirst(myArray)); System.out.println(""); System.out.print("The last integer in the array is: "); System.out.print(getLast(myArray)); System.out.println(""); System.out.print("The array with all but the first integer is: "); System.out.print(getAllButFirst(myArray)); System.out.println(""); System.out.print("The position of the minimum integer is: "); System.out.print(getIndexOfMin(myArray)); System.out.println(""); System.out.print("The position of the maximum integer is: "); System.out.print(getIndexOfMax(myArray)); System.out.println(""); System.out.print("The array after swapping positions 1 and 4 is: "); printArray(swapByIndex(myArray, 1, 4), null); System.out.println(""); System.out.print("The array after removing index3 is: "); printArray(removeAtIndex(myArray, 3), null); System.out.println(""); System.out.print("The array after adding 777 to index position 2 is: "); printArray(insertAtIndex(myArray, 2, 777), null); System.out.println(""); System.out.print("The array is in sorted order: "); System.out.print(isSorted(myArray)); } //#1 public static void printArray(int[] a, String s) { for (int i = 0; i < a.length; i++) { if(i!= a.length-1) { System.out.println(a[i]+s); } else { System.out.print(a[i]); } } } //#2 public static int getFirst(int[] a) { //this method will return int value at index position 0 return a[0]; } //#3 public static int getLast (int[] a) { //this calls array a to use its index integers and then returns the last position of array a return a[a.length-1]; } //#4 public static int[] getAllButFirst(int[] a) { int[] arr4 = new int[a.length-1]; for (int i = 1; i
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
