码迷,mamicode.com
首页 > 移动开发 > 详细

Android Studio下使用Junit框架测试数组和

时间:2017-03-17 19:34:19      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:nbsp   int   color   框架   roi   illegal   out   res   android   

 1 public class Maxsum {
 2     public int maxsum(int[] array) {
 3         if (array == null || array.length == 0) {
 4             throw new IllegalArgumentException("array is null or empty.");
 5         }
 6 
 7 
 8         int result = array[0], mark = 0;
 9 
10         for (int i = 0; i < array.length; i++) {
11             int element = array[i];
12 
13             if (mark >= 0) {
14                 mark += element;
15             } else {
16                 mark = element;
17             }
18 
19             if (mark > result) {
20                 result = mark;
21             }
22         }
23         return result;
24     }
25 
26     public static void main(String[] args) {
27         Maxsum maxsum = new Maxsum();
28         int maxSum = maxsum.maxsum(new int[]{-2,2,-5,3,-4});
29         System.out.println(maxSum);
30     }

 

Android Studio下使用Junit框架测试数组和

标签:nbsp   int   color   框架   roi   illegal   out   res   android   

原文地址:http://www.cnblogs.com/xiaonong/p/6567742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!