package changeanyindex;
import java.util.Scanner;
import java.util.ArrayList;
public class ChangeAnyIndex {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
ArrayList<Integer>Array = new ArrayList<Integer>();
System.out.println("Enter Array Size: ");
int n = s.nextInt();
System.out.println("Enter Array Element: ");
for(int i =0;i<n;i++)
{
int temp = s.nextInt();
Array.add(temp);
}
System.out.println("Your Array: ");
for(int x: Array)
{
System.out.println(x);
}
System.out.println("Enter The Position You want to Change: ");
int cng = s.nextInt();
System.out.println("New Value: ");
int newValue = s.nextInt();
Array.set(cng,newValue); ///change that position value
System.out.println("Your Array After Edit ");
for(int x: Array)
{
System.out.println(x);
}
}
}
Output
Enter Array Size:
3
Enter Array Element:
1 2 4
Enter the position you want to change:
2
New value
3
your array after edit:
1
2
3
Add your comment