zoukankan      html  css  js  c++  java
  • 求整数数组中子数组最大的和

    团队成员:付亚飞  段兴林

      这次的结对项目是求整数数组中子数组最大的和,我们没能在课堂上按时完成题目,把纸上设计的程序运行了一下还存在错误,经过课下的修改能够实现功能了。

    public class  array
     
      {
     
      public static void main(String[] args)
     
        {
     
         int[]a={1 ,-2,3,-4,3,4,6,-2,4,-5};
     
         int max=maxsum(a);
     
        System.out.println("max="+max);
     
        }
     
         public static int maxsum(int a[])
     
        {
     
          int sum=0,max=0;
     
          for(int i=0;i<a.length;i++)
     
            {
     
              sum=sum+a[a.length-i-1];
     
              if(a[a.length-i-1]>0)
     
                if(sum>max)
     
                {
     
                  max=sum;
     
                }
     
               if(sum<0)
     
                {
     
                     sum=0;
     
                }
     
                      return max;
     
                  }
     
                }
     
     }    
     
     
  • 相关阅读:
    电脑休眠真是神一样
    用visual studio 2017来调试python
    判断两个字符串是不是异位词
    算法题思路总结和leecode继续历程
    今日头条笔试题目,还是没过.效率不够
    The init method
    Object-oriented features
    Modifiers
    Pure functions
    Classes and functions
  • 原文地址:https://www.cnblogs.com/feiji/p/3591902.html
Copyright © 2011-2022 走看看