万金流
初次使用博客园,目前感觉还不错。 不知不觉用了4年零4个月了,越来越喜欢博客园。

如题

分为按“下标”和按“值”两种。顺序为“改、查、增、删”(由易到难)

值改代码:

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();
    }

运行结果:

 

 (待续)

posted on 2020-09-22 09:15  万金流  阅读(225)  评论(0编辑  收藏  举报