Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

java - 为什么只采用数组中的第一个元素?(Why it's taking only first element in the array?)

for (int i=0;i<max.length;i++){
    System.out.print(max[i]);
    if(max[i]>low ){
        low = max[i];
        if(low<=b){
            soln=low;
        }
    }   
}
System.out.println();

if(soln==0){
    System.out.println(neg);
} else {
    System.out.println(soln);
}

output 8

(输出8)

Well, I have given value of neg=-1,low=0, b=10, keyboards=2, drive=3 and my array is

(好吧,我给定了neg = -1,low = 0,b = 10,keyboards = 2,drive = 3的值,我的数组是)

[3 1]

([3 1])

[5 2 8]

([5 2 8])

I have added the keyboard and drive value stored it in max array.

(我已经添加了键盘并将驱动器值存储在max数组中。)

When I compare those max array values with b if(max[i]>low), it should return 9 after the completion of loop.

(当我将这些最大数组值与b if(max [i]> low)比较时,它应在循环完成后返回9。)

But it is taking only first element in the max array.

(但是它只占用max数组中的第一个元素。)

I don't know why?

(不知道为什么)

Please help me.

(请帮我。)

  ask by von translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

where you wrote this: (max[i]>low)

(您在何处编写此代码:( (max[i]>low))

it should be this: (max[i]<low)

(应该是这样的: (max[i]<low))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...