Array add

Home > Sci-Tech

Array add

2022-06-23 18:04:08 6 ℃

//statement

int ARR = {99, 85, 82, 63, 60, 0};

int target = 83; // The data to be inserted

int index = -1; // Record the inserted position

// Print the array before inserting

for (int n: arr) {

System.out.print (n + "t");

}

// Traversing the array, inserting

for (int i = 0; I

// Determine whether the target is greater than the current element

if (target> arr [i]) {

//exchange

int Temp = Arr [i];

arr [i] = target;

target = temp;

// Determine whether you need to record the bidding

if (index == -1) {{

Index = i;

}

}

}

// Replace the last element

Arr [Arr.Length-] = Target;

// Print the array after inserting

System.out.println;

}

System.out.println ("N position inserted in:" + index);