Java If Statement [英] Java If Statement

查看:93
本文介绍了Java If Statement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Java编写了一些代码来测试两种解决方案的适用性。

I have written some code in Java which tests the fitness of two solutions.

我希望比较两种解决方案并保持最佳解决方案健身并丢弃另一个。

I am looking to then compare the two solutions and keep the one which has the best fitness and to discard the other.

例如:

if(fitness1 < fitness2)
    keep fitness1 and discard/ignore fitness2
else
    keep fitness2 and discard/ignore fitness1

我将如何实现这一目标?最终我希望有一个最佳健身水平的清单(大小n)。我想我必须在每次迭代中将最佳适应度添加到某种类型的列表中?

How would I go about achieving this? Eventually I hope to have a list (size n) of the best fitness levels. I imagine that I would have to add the best fitness in each iteration to a list of some type?

推荐答案

我会说,创建一个 ArrayList< Double> 以保持最佳值并使用它:

I'd say, create an ArrayList<Double> to keep the best values in and use this:

arrayList.add((fitness1 < fitness2) ? fitness1 : fitness2);

这样你就会得到一个最佳值列表。

That way you'll have a list of the best values.

这篇关于Java If Statement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆