import java.util.Scanner;
public class Insert_Array
{public static void main(String[] args)
{int n, pos, x;
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array:");
n = s.nextInt();
int a[] = new int[n+1];
System.out.println("Enter all the elements:");
for(int i = 0; i < n; i++)
{a[i] = s.nextInt();
}System.out.print("Enter the position where you want to insert element:");
pos = s.nextInt();
System.out.print("Enter the element you want to insert:");
x = s.nextInt();
for(int i = (n-1); i >= (pos-1); i--)
{a[i+1] = a[i];
}a[pos-1] = x;
System.out.print("After inserting:");
for(int i = 0; i < n; i++)
{System.out.print(a[i]+",");
}System.out.print(a[n]);
}}
this site is to help students to learn coding in java platform and qbasic platform. all programs are ICSE and ISC level. Java programs java python Python programs
Insert an element in an array
Subscribe to:
Post Comments (Atom)
Infix postfix prefix
import java.util.Stack; import java.util.Scanner; public class ExpressionConverter { // Function to return precedence of operators ...
-
Chapter 3 Arrays Class 10 - APC Understanding Computer Applications with BlueJ Tick the correct answer Question 1 Which of the following i...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
-
/* Write a program to accept a number and check it is a lead number or not. Lead number is a number in which the sum of the even digits is...
No comments:
Post a Comment
any problem in any program comment:-