Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete the value of the scores array index index position in the Java array

Shulou Source: shulou.com Published: 2022-06-02 03:14:51 09月24日 Update

It is believed that many inexperienced people do not know what to do about how to delete the value of the index position of the scores array index in the Java array. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

/ * * title: delete the value of scores array index index position: 1. Create a temporary array tempArray 2. 0 that is 1 smaller than scores. Copy the data in front of index to the front of tempArray 3. 0. Copy the array after index to 4. 0 after tempArray. Assign the tempArray address pointer reference to scores 5. 0. Printout scores*/import java.util.Scanner;public class ArrayDelete {public static void main (String [] args) {/ / definition and initialization of one-dimensional array int [] scores = {90, 70, 50, 80, 60, 85}; System.out.println ("Please enter the index index:") Scanner in = new Scanner (System.in); int index = in.nextInt (); / / 1. Create a temporary array tempArray int [] tempArray = new int [scores.length-1] that is 1 smaller than scores; / / 2. Copy the data in front of index to the front of tempArray / / 3. Copy the array after index to for after tempArray (int I = 0; I

< scores.length; i++) { if (i < index) tempArray[i] = scores[i]; if (i >

Index) tempArray [I-1] = scores [I];} / / 4. Assign the tempArray address pointer reference to scores scores = tempArray; / / 5. Printout scores for (int I = 0; I < scores.length; iTunes +) {System.out.print (score [I] + ",")} after reading the above, do you know how to delete the value of the index index position of the scores array in the Java array? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Array index location content address pointer data method more problem output helpless for this reason ideas skills articles experience industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno macOS Redmi Shulou Tech Info