Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class InsertIA{
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int N=5;
- int J=N; //step 1
- int[] LA = new int[20];
- int positionOfElement = 2;
- int ITEM = 99;
- for (int i=0;i<J;i++) { //scan part not most important
- LA[i]=scan.nextInt();
- }
- for (int i=0;i<J;i++) {
- System.out.print(LA[i]+" ");
- }
- while(J>(positionOfElement - 1)){ //step 2
- LA[J]=LA[J-1]; //step 3 this statement is important
- J--;//step 4
- }
- LA[positionOfElement-1] = ITEM; //step 5
- System.out.print("\n");
- N=N+1; //step 6
- for (int i=0;i<N;i++) {
- System.out.print(LA[i]+" "); //just print it
- }
- }
- }
- /// main code is///
- /*
- while(J>(positionOfElement - 1)){ //step 2
- LA[J]=LA[J-1]; //step 3 this statement is important
- J--;//step 4
- }
- LA[positionOfElement-1] = ITEM; //step 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement