Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.util.Scanner;
- public class task9 {
- /**
- * @param args the command line arguments
- */
- public static void prA(int a[]){
- for(int i=0; i<a.length; i++)
- System.out.print(a[i]+" ");
- }
- public static void insert2(int a[], int index, int element){
- if(index>=a.length){
- System.out.println("Not possible, size is smaller than the given index");
- }else{
- a[index] = element;
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a[] = {10, 20, 30, 40, 50};
- System.out.println("The source array");
- prA(a);
- System.out.println();
- System.out.println("Enter the specific index");
- int i = sc.nextInt();
- System.out.println("ENter the element");
- int e = sc.nextInt();
- insert2(a, i, e);
- prA(a);
- // TODO code application logic here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement