SHARE
TWEET

Untitled

a guest Sep 21st, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. import java.util.Scanner;
  8. public class task9 {
  9.  
  10.     /**
  11.      * @param args the command line arguments
  12.      */
  13.     public static void prA(int a[]){
  14.         for(int i=0; i<a.length; i++)
  15.             System.out.print(a[i]+" ");
  16.     }
  17.        
  18.     public static void insert2(int a[], int index, int element){
  19.       if(index>=a.length){
  20.         System.out.println("Not possible, size is smaller than the given index");
  21.       }else{
  22.          a[index] = element;
  23.       }
  24.          }
  25.     public static void main(String[] args) {
  26.         Scanner sc = new Scanner(System.in);
  27.         int a[] = {10, 20, 30, 40, 50};
  28.         System.out.println("The source array");
  29.         prA(a);
  30.         System.out.println();
  31.         System.out.println("Enter the specific index");
  32.         int i = sc.nextInt();
  33.         System.out.println("ENter the element");
  34.         int e = sc.nextInt();
  35.         insert2(a, i, e);
  36.         prA(a);
  37.         // TODO code application logic here
  38.     }
  39.    
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top