- /*
- 修改 scores 数组索引 index 位置的值为 value
- */
- import java.util.Scanner;
- public class ArrayUpdate
- {public static void main(String[] args)
- {
- // 一维数组的定义和初始化
- int[] scores={90,70,50,80,60,85};
- System.out.println("请输入要修改的索引位置 index :");
- Scanner in=new Scanner(System.in);
- int index=in.nextInt();
- System.out.println("请输入要修改的值 value :");
- int value=in.nextInt();
- // 修改
- scores[index]=value;
- // 打印输出 scores
- for(int i=0;i<scores.length;i++)
- {
- System.out.print(scores[i]+",");
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2646436.html