Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int[] massive = {1, 2, 3, 4, 5};
- int elementToAdd = 99;
- int indexToInsert = 2;
- System.out.println(Arrays.toString(massive));
- // massive = Arrays.copyOfRange(massive, 1, massive.length);
- for (int i = massive.length - 1; i > indexToInsert ; i--) {
- massive[i] = massive[i-1];
- }
- massive[indexToInsert] = elementToAdd;
- System.out.println(Arrays.toString(massive));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement