zhs313147 2020-08-03 20:23 采纳率: 100%
浏览 125
已采纳

菜鸟提问,java错误提示

不知道是哪里出了问题,请大神解答

public class TestFunctionArray{
    public static void main(String[] args){

        int[] scores = {99,88,99,88,77,-1,-1,-1};
        addElement(scores , 0 , 99 , -1);
    }

    public static void addElement(int[] array , int position , int value ,int flag){

        boolean tag = false;//没有可用空间

        int index = array.length;

        //1.还有没有可用空间(扩容)
        for(int i = 0 ; i < array.length ; i++){

            if(array[i] == flag){

                tag = true;//有可用空间

                index = i;

                break;
            }
        }

        if(!tag){
            //expand
        }

        //2.验证是否为有位置(0~flag)
        if(position < 0 || position > index){
            return;
        }

        //3.移动元素
        for(int i = index-1 ; index >= position ; i--){
            array[i+1] = array[i];
        }
        //4.目标位置赋值
        array[position] = value;
    }

}   
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-08-03 20:36
    关注
    for(int i = index-1 ; index >= position ; i--){
    目测是
    for(int i = index-1 ; i >= position ; i--){
    

    问题解决的话,请点下采纳。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装