神州数码笔试题目(二)

/**
 * 神州数码笔试题目
 * 2.有一百个整数,其中有负数,找出连续三个数之和最大的部分. 
 * 语言:实现语言  java
 *
 
*/


public   class  MaxTest  {
    
    
public int getThreeMax(int[] count){
        
int max = 0;
        
int j = -1;
        
for(int i=0;i<count.length;i++){
            
if((i + 2< count.length){
                
if(count[i] < 0){
                    
continue;
                }
    
                
else if(count[i+1< 0){
                    i 
= i + 1;
                    
continue;    
                }

                
else if(count[i+2< 0){
                    i 
= i + 2;
                    
continue;    
                }

                
else{
                    
if(max < (count[i] + count[i+1]+count[i+2])){
                        max 
= (count[i] + count[i+1]+count[i+2]);
                        j 
= i;    
                    }
    
                }

            }
else{
                
break;    
            }

        }
//end for
        return j;
    }

    
    
public static void main(String[] args){
        MaxTest max 
= new MaxTest();
        
int[] count = {-3,4,6,8,-9,7,10,-6,20,-9};
        
int mark = max.getThreeMax(count);
        
if(mark == -1){
            System.out.println(
"the count you do is not right");    
        }
else{
            System.out.println(count[mark]);    
            System.out.println(count[mark
+1]);    
            System.out.println(count[mark
+2]);    
        }

    }

}

// 更多笔试题目:www.search.bdkey.com
 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值