Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class SpecifiedPosition {
- public static void main(String[] args) {
- int n;
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the number of elements");
- n=src.nextInt();
- int a[]=new int[n];
- for(int i=0;i<n;i++)
- {
- System.out.println("Enter the element");
- a[i]=src.nextInt();
- }
- System.out.println("The elements are");
- for(int j=0;j<n;j++)
- {
- System.out.println(a[j]);
- }
- System.out.println("Enter the position at which you want to put element");
- int p=src.nextInt();
- System.out.println("Enter the element");
- int ele=src.nextInt();
- a[p-1]=ele;
- System.out.println("Elements in the array after inserting are");
- for(int k=0;k<n;k++)
- {
- System.out.println(a[k]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement