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