Sunday, 4 March 2018

Array in java , Replace Array Element by Index program





package javaapplication10;



import java.util.Scanner;





public class JavaApplication10 {



   

    public static void main(String[] args)

    {

        int n,index;

        Scanner obj=new Scanner( System.in);

        int []x=new int[]{10,20,40,30};

        System.out.println("Enter the number that you want to Replace in array: ");

        n=obj.nextInt();

        System.out.println("Enter the index on which you want to replace the number "+n);

        index=obj.nextInt();

   

        if (index>-1 && index<x.length)

        {

          x[index]=n; 

       

         

        }

        else

        {

            System.out.println("Invalid input.......");

        }       

     

          for(int c:x)

        {

       

            System.out.print(c+" ");

        }

       

       

           

       

       

       

    }

   

}


No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...