如题
分为按“下标”和按“值”两种。顺序为“改、查、增、删”(由易到难)
值改代码:
public static void main(String[] args) { // TODO Auto-generated method stub int[] a= {1,3,5,2,4,6}; int n,v; Scanner scan=new java.util.Scanner(System.in); System.out.println("数组为:"); showArray(a); System.out.println("输入下标:"); n=scan.nextInt(); System.out.println("输入要修改的值:"); v=scan.nextInt(); a[n]=v; System.out.println("数组为:"); showArray(a); scan.close(); } public static void showArray(int[] x) { for (int i : x) { System.out.print(i+"\t"); } System.out.println(); }
运行结果:
(待续)